#25105: Migrating multiple CharFields to null=False breaks on PostgreSQL
----------------------------+--------------------
     Reporter:  danielr     |      Owner:  nobody
         Type:  Bug         |     Status:  new
    Component:  Migrations  |    Version:  1.8
     Severity:  Normal      |   Keywords:
 Triage Stage:  Unreviewed  |  Has patch:  0
Easy pickings:  0           |      UI/UX:  0
----------------------------+--------------------
 Given a model containing multiple CharFields defined as {{{null=True}}},
 and at least one row with null data in two or more of those fields, then
 change the CharFields to null=False and create a migration with a
 temporary default of the empty string.

 Running this migration will attempt, for each field, to set the null
 values to the empty string, then migrate the field to NOT NULL. However,
 the second field will fail with the error {{{psycopg2.OperationalError:
 cannot ALTER TABLE "fundraising_donation" because it has pending trigger
 events}}}.

 Clearly this is the same issue warned against in the
 [https://docs.djangoproject.com/en/1.8/ref/migration-operations/#runpython
 migration documentation] as caused by mixing RunPython  and schema changes
 in the same migration; however, here it is a fully automatically-generated
 migration which causes the error.

 Some possible solutions:

 * Do nothing but mention this edge case in the documentation;
 * Detect and warn against converting multiple null=False fields in one
 migration;
 * Detect and deal with the problem in some way, perhaps by committing the
 transaction after each field.

--
Ticket URL: <https://code.djangoproject.com/ticket/25105>
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/050.3a29a078520991c444b5574f0e49eb9e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to