Change SQL generation when primary_key=True and unique=True
|Reported by:||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
At the moment, these two models, which are logically equivalent, generate different sql:
class Country(models.Model): isocode = CharField(max_length=3, primary_key=True, unique=True)
class Country(models.Model): isocode = CharField(max_length=3, primary_key=True)
- at least for backends other than Oracle
I would like to suggest that we do not create explicit UNIQUE constraints for (single field) primary keys.
On the other hand, I think it would be nice if field.unique returned True for a primary key field no matter if it was defined as such or not.
I will write a patch doing this, but am of course open to alternative suggestions.