Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#23065 closed Bug (fixed)

Migration Error when removing unique constraint

Reported by: anonymous Owned by: nobody
Component: Migrations Version: 1.7
Severity: Release blocker Keywords: migrations
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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

Change History (10)

comment:1 by anonymous, 10 years ago

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.

comment:2 by Tim Graham, 10 years ago

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.

comment:3 by Tim Graham, 10 years ago

Resolution: worksforme
Status: newclosed

comment:4 by Sergey Fedoseev, 10 years ago

Resolution: worksforme
Status: closednew
Triage Stage: UnreviewedAccepted

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

comment:5 by Sergey Fedoseev, 10 years ago

Has patch: set

comment:6 by Sergey Fedoseev, 10 years ago

Version: 1.7-rc-11.7

comment:7 by Tim Graham, 10 years ago

Needs tests: set
Severity: NormalRelease blocker

Regression tests are also required.

comment:8 by Sergey Fedoseev, 10 years ago

Needs tests: unset

tests and release notes entry added in the pull request

comment:9 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: newclosed

In 83cd18633fb13924d8a50a1cd4ed21cb9552a635:

Fixed #23065 -- Quoted constraint names in SQL generated by migrations.

comment:10 by Tim Graham <timograham@…>, 10 years ago

In 58d7b84d53832a056128192c335127f10e082f2c:

[1.7.x] Fixed #23065 -- Quoted constraint names in SQL generated by migrations.

Backport of 83cd18633f from master

Note: See TracTickets for help on using tickets.
Back to Top