#34128: django re-using the name of a squashed migration leads to
CircularDependencyError
-------------------------------------+-------------------------------------
Reporter: discordianfish | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
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
-------------------------------------+-------------------------------------
Description changed by discordianfish:
Old 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.
New 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.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/34128#comment:1>
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/010701842e2e8ec9-aa5a5352-a59a-4136-b213-26184c77ec5a-000000%40eu-central-1.amazonses.com.