[Django] #24102: BaseDatabaseSchemaEditor.create_model: allow unique_together constraint name

45 views
Skip to first unread message

Django

unread,
Jan 8, 2015, 12:29:42 PM1/8/15
to django-...@googlegroups.com
#24102: BaseDatabaseSchemaEditor.create_model: allow unique_together constraint
name
-------------------------------+--------------------
Reporter: dnozay | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.7
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
In `BaseDatabaseSchemaEditor.create_model` there are currently no names
for `unique_together` constraints.

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.

Django

unread,
Jan 8, 2015, 12:31:18 PM1/8/15
to django-...@googlegroups.com
#24102: BaseDatabaseSchemaEditor.create_model: allow unique_together constraint
name
-------------------------------+--------------------------------------

Reporter: dnozay | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by dnozay):

* 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>

Django

unread,
Jan 8, 2015, 12:42:34 PM1/8/15
to django-...@googlegroups.com
#24102: BaseDatabaseSchemaEditor.create_model: allow unique_together constraint
name
-------------------------------+--------------------------------------

Reporter: dnozay | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

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>

Django

unread,
Jan 9, 2015, 8:04:40 AM1/9/15
to django-...@googlegroups.com
#24102: BaseDatabaseSchemaEditor.create_model: allow unique_together constraint
name
--------------------------------------+------------------------------------
Reporter: dnozay | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* 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>

Django

unread,
Jan 9, 2015, 8:05:27 AM1/9/15
to django-...@googlegroups.com
#24102: SchemaEditor.create_model doesn't create a constraint name for
unique_together
--------------------------------------+------------------------------------
Reporter: dnozay | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/24102#comment:4>

Django

unread,
Jan 9, 2015, 11:26:45 AM1/9/15
to django-...@googlegroups.com
#24102: SchemaEditor.create_model doesn't create a constraint name for
unique_together
--------------------------------------+------------------------------------
Reporter: dnozay | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

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>

Django

unread,
Jan 9, 2015, 12:49:25 PM1/9/15
to django-...@googlegroups.com
#24102: SchemaEditor.create_model doesn't create a constraint name for
unique_together
--------------------------------------+------------------------------------
Reporter: dnozay | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

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>

Django

unread,
Mar 25, 2015, 12:49:38 PM3/25/15
to django-...@googlegroups.com
#24102: SchemaEditor.create_model doesn't create a constraint name for
unique_together
--------------------------------------+------------------------------------
Reporter: dnozay | Owner: nobody
Type: Cleanup/optimization | Status: closed
Component: Migrations | Version: 1.7
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* status: new => closed
* resolution: => fixed


Comment:

Fixed in 01ec127baec38b7f8281e6eca9def40f22c9e5ad.

--
Ticket URL: <https://code.djangoproject.com/ticket/24102#comment:7>

Reply all
Reply to author
Forward
0 new messages