[Django] #23065: Migration Error when removing unique constraint

8 views
Skip to first unread message

Django

unread,
Jul 21, 2014, 9:18:38 AM7/21/14
to django-...@googlegroups.com
#23065: Migration Error when removing unique constraint
----------------------------+------------------------
Reporter: anonymous | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-rc-1
Severity: Normal | Keywords: migrations
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------
I try to make a migration which simple removes "unique = True" from a
field. and get the error below.

Note this is nothing to do with Django's standard auth module, but a
custom implementation, as far as I can see that should have nothing to do
with it.

This is a private project so I can't give many more details than this. I'm
using Postgres and the current 1.7 rc.

{{{
python manage.py makemigrations
Migrations for 'Auth':
0003_auto_20140721_1413.py:
- Alter field name on permission
(env)samuel || python manage.py migrate
Operations to perform:
Synchronize unmigrated apps: bootstrapform, django_jinja, admin_tools,
theming, dashboard
Apply all migrations: Schedule, admin, sessions, auth, contenttypes,
Accounts, Auth, CRM
Synchronizing apps without migrations:
Creating tables...
Installing custom SQL...
Installing indexes...
Running migrations:
Applying Auth.0003_auto_20140721_1413...Traceback (most recent call
last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/path/to/project/env/local/lib/python2.7/site-
packages/django/core/management/__init__.py", line 385, in
execute_from_command_line
utility.execute()
File "/path/to/project/env/local/lib/python2.7/site-
packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/path/to/project/env/local/lib/python2.7/site-
packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/path/to/project/env/local/lib/python2.7/site-
packages/django/core/management/base.py", line 337, in execute
output = self.handle(*args, **options)
File "/path/to/project/env/local/lib/python2.7/site-
packages/django/core/management/commands/migrate.py", line 160, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "/path/to/project/env/local/lib/python2.7/site-
packages/django/db/migrations/executor.py", line 62, in migrate
self.apply_migration(migration, fake=fake)
File "/path/to/project/env/local/lib/python2.7/site-
packages/django/db/migrations/executor.py", line 96, in apply_migration
migration.apply(project_state, schema_editor)
File "/path/to/project/env/local/lib/python2.7/site-
packages/django/db/migrations/migration.py", line 107, in apply
operation.database_forwards(self.app_label, schema_editor,
project_state, new_state)
File "/path/to/project/env/local/lib/python2.7/site-
packages/django/db/migrations/operations/fields.py", line 131, in
database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/path/to/project/env/local/lib/python2.7/site-
packages/django/db/backends/schema.py", line 506, in alter_field
self._alter_field(model, old_field, new_field, old_type, new_type,
old_db_params, new_db_params, strict)
File "/path/to/project/env/local/lib/python2.7/site-
packages/django/db/backends/schema.py", line 525, in _alter_field
"name": constraint_name,
File "/path/to/project/env/local/lib/python2.7/site-
packages/django/db/backends/schema.py", line 98, in execute
cursor.execute(sql, params)
File "/path/to/project/env/local/lib/python2.7/site-
packages/django/db/backends/utils.py", line 81, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/path/to/project/env/local/lib/python2.7/site-
packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/path/to/project/env/local/lib/python2.7/site-
packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/path/to/project/env/local/lib/python2.7/site-
packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: constraint "auth_permission_name_key" of
relation "Auth_permission" does not exist

}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23065>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 21, 2014, 9:26:59 AM7/21/14
to django-...@googlegroups.com
#23065: Migration Error when removing unique constraint
----------------------------+--------------------------------------

Reporter: anonymous | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-rc-1
Severity: Normal | Resolution:

Keywords: migrations | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Oh, i can probably say the model looked liek this,


{{{
class Permission(models.Model):
sys_name = models.CharField(_('System Name'), unique = True,
max_length = 20)
name = models.CharField(_('Name'), unique = True, max_length = 50)

def __unicode__(self):
return self.name
}}}

I wanted to remove the unique constraint from name.

--
Ticket URL: <https://code.djangoproject.com/ticket/23065#comment:1>

Django

unread,
Jul 21, 2014, 3:08:09 PM7/21/14
to django-...@googlegroups.com
#23065: Migration Error when removing unique constraint
----------------------------+--------------------------------------

Reporter: anonymous | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-rc-1
Severity: Normal | Resolution:

Keywords: migrations | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by timo):

I couldn't reproduce this (adding and removing a unique constraint. Does a
unique constraint exist in the database? Maybe it has a different name?
More details with steps to reproduce would be helpful.

--
Ticket URL: <https://code.djangoproject.com/ticket/23065#comment:2>

Django

unread,
Jul 23, 2014, 8:16:39 AM7/23/14
to django-...@googlegroups.com
#23065: Migration Error when removing unique constraint
----------------------------+--------------------------------------
Reporter: anonymous | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.7-rc-1
Severity: Normal | Resolution: worksforme

Keywords: migrations | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

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


--
Ticket URL: <https://code.djangoproject.com/ticket/23065#comment:3>

Django

unread,
Sep 16, 2014, 10:53:39 AM9/16/14
to django-...@googlegroups.com
#23065: Migration Error when removing unique constraint
----------------------------+------------------------------------

Reporter: anonymous | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-rc-1
Severity: Normal | Resolution:
Keywords: migrations | Triage Stage: Accepted

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

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

* status: closed => new
* resolution: worksforme =>
* stage: Unreviewed => Accepted


Comment:

steps to reproduce postgres should be used as backend (maybe others, but
not sqlite):

* add `Auth` app with model as shown above
* syncdb using django 1.6
* upgrade to django 1.7
* makemigrations Auth
* migrate --fake
* remove any unique constraint
* makemigrations Auth
* migrate

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

Django

unread,
Sep 16, 2014, 10:56:46 AM9/16/14
to django-...@googlegroups.com
#23065: Migration Error when removing unique constraint
----------------------------+------------------------------------

Reporter: anonymous | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-rc-1
Severity: Normal | Resolution:
Keywords: migrations | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* has_patch: 0 => 1


Comment:

pull request is here: https://github.com/django/django/pull/3226

--
Ticket URL: <https://code.djangoproject.com/ticket/23065#comment:5>

Django

unread,
Sep 16, 2014, 11:23:52 AM9/16/14
to django-...@googlegroups.com
#23065: Migration Error when removing unique constraint
----------------------------+------------------------------------

Reporter: anonymous | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:
Keywords: migrations | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* version: 1.7-rc-1 => 1.7


--
Ticket URL: <https://code.djangoproject.com/ticket/23065#comment:6>

Django

unread,
Sep 16, 2014, 11:43:53 AM9/16/14
to django-...@googlegroups.com
#23065: Migration Error when removing unique constraint
---------------------------------+------------------------------------

Reporter: anonymous | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Release blocker | Resolution:

Keywords: migrations | 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):

* severity: Normal => Release blocker
* needs_tests: 0 => 1


Comment:

Regression tests are also required.

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

Django

unread,
Sep 17, 2014, 10:28:27 AM9/17/14
to django-...@googlegroups.com
#23065: Migration Error when removing unique constraint
---------------------------------+------------------------------------

Reporter: anonymous | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Release blocker | Resolution:
Keywords: migrations | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_tests: 1 => 0


Comment:

tests and release notes entry added in the pull request

--
Ticket URL: <https://code.djangoproject.com/ticket/23065#comment:8>

Django

unread,
Sep 23, 2014, 9:26:01 AM9/23/14
to django-...@googlegroups.com
#23065: Migration Error when removing unique constraint
---------------------------------+------------------------------------
Reporter: anonymous | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.7
Severity: Release blocker | Resolution: fixed

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

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed

* resolution: => fixed


Comment:

In [changeset:"83cd18633fb13924d8a50a1cd4ed21cb9552a635"]:
{{{
#!CommitTicketReference repository=""
revision="83cd18633fb13924d8a50a1cd4ed21cb9552a635"
Fixed #23065 -- Quoted constraint names in SQL generated by migrations.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23065#comment:9>

Django

unread,
Sep 23, 2014, 10:12:21 AM9/23/14
to django-...@googlegroups.com
#23065: Migration Error when removing unique constraint
---------------------------------+------------------------------------
Reporter: anonymous | Owner: nobody

Type: Bug | Status: closed
Component: Migrations | Version: 1.7
Severity: Release blocker | Resolution: fixed
Keywords: migrations | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by Tim Graham <timograham@…>):

In [changeset:"58d7b84d53832a056128192c335127f10e082f2c"]:
{{{
#!CommitTicketReference repository=""
revision="58d7b84d53832a056128192c335127f10e082f2c"
[1.7.x] Fixed #23065 -- Quoted constraint names in SQL generated by
migrations.

Backport of 83cd18633f from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23065#comment:10>

Reply all
Reply to author
Forward
0 new messages