#34128: django re-using the name of a squashed migration leads to
CircularDependencyError
-------------------------------------+-------------------------------------
               Reporter:             |          Owner:  nobody
  discordianfish                     |
                   Type:             |         Status:  new
  Uncategorized                      |
              Component:  Database   |        Version:  3.2
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Hi,

 I've squashed two migrations,  creating this file:
 ```
 # Generated by Django 3.2 on 2022-10-30 14:15

 from django.db import migrations, models


 class Migration(migrations.Migration):

     replaces = [('api', '0005_achievement_difficulty'), ('api',
 '0006_alter_achievement_difficulty')]

     dependencies = [
         ('api',
 '0004_achievement_squashed_0005_alter_achievement_submission'),
     ]

     operations = [
         migrations.AddField(
             model_name='achievement',
             name='difficulty',
             field=models.SmallIntegerField(default=0),
         ),
     ]
 ```

 After rolling out the change, I've deleted 0005_achievement_difficulty and
 0006_alter_achievement_difficulty.

 Now I've did some more changes to the model, causing django to create the
 following 0006_alter_achievement_difficulty:
 ```
 # Generated by Django 3.2 on 2022-10-31 12:59

 from django.db import migrations, models


 class Migration(migrations.Migration):

     dependencies = [
         ('api',
 '0005_achievement_difficulty_squashed_0006_alter_achievement_difficulty'),
     ]

     operations = [
         migrations.AlterField(
             model_name='achievement',
             name='difficulty',
             field=models.SmallIntegerField(),
         ),
     ]
 ```

 Which leads to the following error:
 ```
   File "/usr/local/lib/python3.10/site-
 packages/django/db/migrations/graph.py", line 274, in ensure_not_cyclic
     raise CircularDependencyError(", ".join("%s.%s" % n for n in cycle))
 django.db.migrations.exceptions.CircularDependencyError:
 api.0005_achievement_difficulty_squashed_0006_alter_achievement_difficulty
 ```

 Renaming the migration file to 0006_alter_achievement_difficulty_new.py
 fixed it.

 While I wouldn't rule out a mistake on my side, it seems the way django
 creates the migration name can lead to new migrations being named like
 squashed and removed ones, causing the dependency check to wrongfully
 assume the squashed migration would depend on it.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34128>
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/010701842e2d92de-c538ff9b-71f6-466c-af37-c4cfcea81b42-000000%40eu-central-1.amazonses.com.

Reply via email to