Opened 10 years ago
Closed 10 years ago
#24102 closed Cleanup/optimization (fixed)
SchemaEditor.create_model doesn't create a constraint name for unique_together
Reported by: | Damien Nozay | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 1.7 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In BaseDatabaseSchemaEditor.create_model
there are currently no names for unique_together
constraints.
http://stackoverflow.com/a/27836476/1733117
class BaseDatabaseSchemaEditor(object): # Overrideable SQL templates sql_create_table_unique = "UNIQUE (%(columns)s)" sql_create_unique = "ALTER TABLE %(table)s ADD CONSTRAINT %(name)s UNIQUE (%(columns)s)" sql_delete_unique = "ALTER TABLE %(table)s DROP CONSTRAINT %(name)s"
create_model
has this bit:
# Add any unique_togethers for fields in model._meta.unique_together: columns = [model._meta.get_field(field).column for field in fields] column_sqls.append(self.sql_create_table_unique % { "columns": ", ".join(self.quote_name(column) for column in columns), })
whereas adding a new unique_together constraint does this:
def _create_unique_sql(self, model, columns): return self.sql_create_unique % { "table": self.quote_name(model._meta.db_table), "name": self.quote_name(self._create_index_name(model, columns, suffix="_uniq")), "columns": ", ".join(self.quote_name(column) for column in columns), }
Change History (7)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
haven't tested it myself - but maybe the CI system will:
https://github.com/django/django/pull/3862
comment:3 by , 10 years ago
Component: | Uncategorized → Migrations |
---|---|
Has patch: | set |
Needs tests: | set |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/optimization |
comment:4 by , 10 years ago
Summary: | BaseDatabaseSchemaEditor.create_model: allow unique_together constraint name → SchemaEditor.create_model doesn't create a constraint name for unique_together |
---|
follow-up: 6 comment:5 by , 10 years ago
If we add unique_together
constraints in create model, can we add index_together
as well, please.
comment:6 by , 10 years ago
Replying to MarkusH:
If we add
unique_together
constraints in create model, can we addindex_together
as well, please.
please file a separate ticket. IMHO this is a separate concern / request.
comment:7 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Fixed in 01ec127baec38b7f8281e6eca9def40f22c9e5ad.
In
BaseDatabaseSchemaEditor.create_model
there are currently no names forunique_together
constraints.possible fix:
create_model
should have: