http://stackoverflow.com/a/27836476/1733117
{{{#!python
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:
{{{#!python
# 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:
{{{#!python
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),
}
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24102>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
In `BaseDatabaseSchemaEditor.create_model` there are currently no names
for `unique_together` constraints.
possible fix:
{{{#!python
class BaseDatabaseSchemaEditor(object):
# Overrideable SQL templates
sql_create_table_unique = "UNIQUE %(name)s (%(columns)s)"
}}}
`create_model` should have:
{{{#!python
# 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 % {
"name": self.quote_name(self._create_index_name(model,
columns, suffix="_uniq")),
"columns": ", ".join(self.quote_name(column) for column in
columns),
})
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24102#comment:1>
Comment (by dnozay):
haven't tested it myself - but Travis will:
https://github.com/django/django/pull/3862
--
Ticket URL: <https://code.djangoproject.com/ticket/24102#comment:2>
* type: Uncategorized => Cleanup/optimization
* has_patch: 0 => 1
* component: Uncategorized => Migrations
* needs_tests: 0 => 1
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/24102#comment:3>
--
Ticket URL: <https://code.djangoproject.com/ticket/24102#comment:4>
Comment (by MarkusH):
If we add `unique_together` constraints in create model, can we add
`index_together` as well, please.
--
Ticket URL: <https://code.djangoproject.com/ticket/24102#comment:5>
Comment (by dnozay):
Replying to [comment:5 MarkusH]:
> If we add `unique_together` constraints in create model, can we add
`index_together` as well, please.
please file a separate ticket. IMHO this is a separate concern / request.
--
Ticket URL: <https://code.djangoproject.com/ticket/24102#comment:6>
* status: new => closed
* resolution: => fixed
Comment:
Fixed in 01ec127baec38b7f8281e6eca9def40f22c9e5ad.
--
Ticket URL: <https://code.djangoproject.com/ticket/24102#comment:7>