#29790: Migration that switches a model to a UUID primary key fails with 
"duplicate
column name: id"
-------------------------------------+-------------------------------------
     Reporter:  Richard Ebeling      |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Migrations           |                  Version:  2.1
     Severity:  Normal               |               Resolution:
     Keywords:  multiple primary     |             Triage Stage:  Accepted
  keys migration id uuid             |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

 If you want to maintain Django 1.11 support you could add a `RunPython`
 operation that does something along the following before the swapped
 `AlterField`

 {{{#!python
 def delete_primary_key(apps, schema_editor):
     model = apps.get_model('django_rest_passwordreset',
 'ResetPasswordToken')
     opts = model._meta
     connection = schema_editor.connection
     # Retrieve primary key constraint.
     with connection.cursor() as cursor:
         constraints = connection.introspection.get_constraints(cursor,
 opts.db_table)
     for constraint_name, constraint in constraints.items():
         if constraint.get('primary_key'):
             break
     else:
         raise Exception('Missing primary key constraint')
     # Delete primary key constraint
     quote_name = connection.ops.quote_name
     schema_editor.execute(schema_editor.sql_delete_pk.format(
         table_name=quote_name(table_name),
         name=quote_name(constraint_name),
     ))

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.c6dfb7c5c296d3b2e3b06f6256d9f8ca%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to