#29790: Release notes missing information about change in duplicate pk behavior 
in
2.1
-------------------------------------+-------------------------------------
     Reporter:  Richard Ebeling      |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Documentation        |                  Version:  2.1
     Severity:  Normal               |               Resolution:
     Keywords:  multiple primary     |             Triage Stage:
  keys migration id uuid             |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Old description:

> We migrated a model from a AutoField as id (default behaviour) to a
> UUIDField in the past, using a migration that looked like this with
> django 2.0:
> https://gist.github.com/smcoll/8bb867dc631433c01fd0
>
> There was a bug in SQLite though, which as of today only has the
> workaround listed in the bug tracker: #28541
>
> Thus, we ended up writing our migration like this: https://github.com
> /fsr-
> itse/EvaP/blob/master/evap/evaluation/migrations/0062_replace_textanswer_id_with_uuid.py
>
> When we try updating to django 2.1 now, this migration fails whenever you
> call migrate with the error
> {{{django.db.utils.ProgrammingError: multiple primary keys for table
> "evaluation_textanswer" are not allowed}}}
>
> This commit changed the behavior:
> 02365d3f38a64a5c2f3e932f23925a381d5bb151
>
> It works if we add a RemoveField instruction for the old id before
> setting {{{primary_key=True}}} on the new UUIDField. But this will
> trigger the SQLite bug listed above. Changing the old AutoField to
> {{{primary_key=False}}} where the RemoveField instruction would be
> doesn't fix the error.
>
> The documentation states that
> [https://docs.djangoproject.com/en/stable/ref/models/fields/#django.db.models.Field.primary_key
> an object may not have more than one primary key].
>
> Still, in the release notes for django 2.1 it should be noted that
> django's behavior was changed here. Also, I would appreciate if there was
> some kind of documentation on how you should migrate primary keys from a
> field to another if no two primary keys are allowed in between. There
> should be a way without squashing the migrations as we want to keep the
> history.

New description:

 We migrated a model from a AutoField as id (default behaviour) to a
 UUIDField in the past, using a migration that looked like this with django
 2.0:
 https://gist.github.com/smcoll/8bb867dc631433c01fd0

 There was a bug in SQLite though, which as of today only has the
 workaround listed in the bug tracker: #28541

 Thus, we ended up writing our migration like this: https://github.com/fsr-
 
itse/EvaP/blob/master/evap/evaluation/migrations/0062_replace_textanswer_id_with_uuid.py

 When we try updating to django 2.1 now, this migration fails whenever you
 call migrate with the error
 {{{django.db.utils.ProgrammingError: multiple primary keys for table
 "evaluation_textanswer" are not allowed}}}

 This commit changed the behavior: 02365d3f38a64a5c2f3e932f23925a381d5bb151

 It works if we add a RemoveField instruction for the old id before setting
 {{{primary_key=True}}} on the new UUIDField. But this will trigger the
 SQLite bug listed above. Changing the old AutoField to
 {{{primary_key=False}}} where the RemoveField instruction would be doesn't
 fix the error.

 The documentation states that
 
[https://docs.djangoproject.com/en/stable/ref/models/fields/#django.db.models.Field.primary_key
 an object may not have more than one primary key].

 Still, in the release notes for django 2.1 it should be noted that
 django's behavior was changed here. Also, I would appreciate if there was
 some kind of documentation on how you should migrate primary keys from a
 field to another if no two primary keys are allowed in between. There
 should be a way without squashing the migrations as we want to keep the
 history.

 We are running postgres version 9.6.9 and psycopg2-binary version 2.7.5.
 The migration error will not occur when using a SQLite database.

--

Comment (by Richard Ebeling):

 I can not reproduce this bug with SQLite either, sorry for not testing
 that before. We are running postgres version 9.6.9 and use psycopg2-binary
 version 2.7.5.. I added this information to the initial post.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29790#comment:6>
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.47bc5b42673d36644feae92943a3ae39%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to