Opened 2 years ago
Last modified 2 years ago
#34128 closed Uncategorized
django re-using the name of a squashed migration leads to CircularDependencyError — at Initial Version
Reported by: | Johannes 'fish' Ziemke | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 3.2 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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.