[Django] #34128: django re-using the name of a squashed migration leads to CircularDependencyError

9 views
Skip to first unread message

Django

unread,
Oct 31, 2022, 9:14:13 AM10/31/22
to django-...@googlegroups.com
#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.

Django

unread,
Oct 31, 2022, 9:15:17 AM10/31/22
to django-...@googlegroups.com
#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:

New description:

Hi,


class Migration(migrations.Migration):


class Migration(migrations.Migration):

--

--
Ticket URL: <https://code.djangoproject.com/ticket/34128#comment:1>

Django

unread,
Nov 1, 2022, 1:32:53 AM11/1/22
to django-...@googlegroups.com
#34128: django re-using the name of a squashed migration leads to
CircularDependencyError
-------------------------------------+-------------------------------------
Reporter: Johannes 'fish' | Owner: nobody
Ziemke |
Type: Uncategorized | Status: closed

Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => invalid


Comment:

Thanks for this ticket, however transition of the squashed migration to a
normal migration is more complicated and requires removing the `replaces`
attribute, see [https://docs.djangoproject.com/en/dev/topics/migrations
/#squashing-migrations docs]:

> You must then transition the squashed migration to a normal migration
> - Deleting all the migration files it replaces.
> - Updating all migrations that depend on the deleted migrations to
depend on the squashed migration instead
> - **Removing the `replaces` attribute in the `Migration` class of the
squashed migration (this is how Django tells that it is a squashed
migration).**

--
Ticket URL: <https://code.djangoproject.com/ticket/34128#comment:2>

Reply all
Reply to author
Forward
0 new messages