#31317: Migration using CreateModel with unique_together followed by
AlterUniqueTogether crashes
-------------------------------------+-------------------------------------
     Reporter:  Adam (Chainz)        |                    Owner:  nobody
  Johnson                            |
         Type:  Bug                  |                   Status:  new
    Component:  Migrations           |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Adam (Chainz) Johnson):

 2.2, 3.0, master

 It isn't squashed in this case because the `unique_together` includes a
 FK.

 https://github.com/adamchainz/django-unique-together-
 bug/blob/master/testproj/testapp/migrations/0001_squashed_0002_add_author.py

 {{{#!python
 # Generated by Django 2.1.15 on 2020-02-28 06:56

 from django.db import migrations, models
 import django.db.models.deletion


 class Migration(migrations.Migration):

     replaces = [("testapp", "0001_initial"), ("testapp",
 "0002_add_author")]

     initial = True

     dependencies = []

     operations = [
         migrations.CreateModel(
             name="Book",
             fields=[
                 (
                     "id",
                     models.AutoField(
                         auto_created=True,
                         primary_key=True,
                         serialize=False,
                         verbose_name="ID",
                     ),
                 ),
                 ("title", models.CharField(default="", max_length=100)),
             ],
             options={"unique_together": {("title",)},},
         ),
         migrations.CreateModel(
             name="Author",
             fields=[
                 (
                     "id",
                     models.AutoField(
                         auto_created=True,
                         primary_key=True,
                         serialize=False,
                         verbose_name="ID",
                     ),
                 ),
             ],
         ),
         migrations.AddField(
             model_name="book",
             name="author",
             field=models.ForeignKey(
                 null=True,
                 on_delete=django.db.models.deletion.DO_NOTHING,
                 to="testapp.Author",
             ),
         ),
         migrations.AlterUniqueTogether(
             name="book", unique_together={("title", "author")},
         ),
     ]

 }}}

 It's also possible to hand write such a migration.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31317#comment:2>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.4e026d213da1e329c70e7d66d62ba0a3%40djangoproject.com.

Reply via email to