Opened 10 years ago
Last modified 3 weeks ago
#23337 new Bug
CircularDependencyError when squashing migrations
Reported by: | no | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | info+coding@…, python@…, tarkatronic@…, Sergey Fedoseev, danniranderis, bcail, Gordon Wrigley | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Project layout:
.
├── cheese
│ ├── init.py
│ ├── migrations
│ │ └── init.py
│ └── models.py (model Cheese, links to eggs.Store and spam.Employee)
├── djtest
│ ├── basemodel.py
│ ├── init.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── eggs
│ ├── init.py
│ ├── migrations
│ │ └── init.py
│ └── models.py (model Store, links to spam.Employee)
├── manage.py
└── spam
├── init.py
├── migrations
│ └── init.py
└── models.py (model Employee, links to itself and eggs.Store; model Eggs, links to spam.Employee and cheese.Cheese)
Issue the following commands for the attached project:
$ python manage.py makemigrations
$ manage squashmigrations cheese 0003
$ manage squashmigrations eggs 0002
The following is raised:
django.db.migrations.graph.CircularDependencyError: [('spam', '0001_initial'), ('cheese', '0001_squashed_0003_cheese_updated_by'), ('spam', '0001_initial')]
Attachments (1)
Change History (21)
by , 10 years ago
Attachment: | djtest.zip added |
---|
comment:1 by , 10 years ago
Thanks for the detailed report. Just to make sure, did you reproduce against 1.7-rc-2
or 1.7-rc-3
?
comment:2 by , 10 years ago
Version: | 1.7-rc-2 → 1.7-rc-3 |
---|
It was 1.7-rc-3, The option wasn't available when I reported.
comment:3 by , 10 years ago
Severity: | Normal → Release blocker |
---|---|
Triage Stage: | Unreviewed → Accepted |
Managed to reproduce.
comment:4 by , 10 years ago
Ah, yes, squashing migrations does occasionally result in circular dependencies and there's no way we can solve this in 1.7 (it requires some specialised coding we just don't have). I'll add a note to the docs about this and bump it down from Release Blocker to a more general issue we need to solve next release.
comment:6 by , 10 years ago
Severity: | Release blocker → Normal |
---|---|
Version: | 1.7-rc-3 → master |
comment:8 by , 10 years ago
Cc: | added |
---|
comment:9 by , 10 years ago
Cc: | added |
---|
comment:10 by , 9 years ago
Cc: | added |
---|
comment:11 by , 7 years ago
Cc: | added |
---|
comment:12 by , 6 years ago
Cc: | added |
---|
comment:13 by , 10 months ago
It looks like the first squashmigrations
command for the cheese app results in a circular dependency, so a migrate
or makemigrations
command fails with the CircularDependencyError (even without squashing migrations in the eggs app).
Would it be helpful to add a check in the squashmigrations
command to look at its output and throw an error instead of writing out a squashed migration that causes a CircularDependencyError?
comment:14 by , 9 months ago
Cc: | added |
---|
comment:16 by , 7 months ago
Cc: | added |
---|
comment:17 by , 4 weeks ago
Here's an example PR that checks for circular dependencies when creating squashed migrations, and raises an error if there's a circular dependency. Is that a helpful direction? Would it be better to leave the squashed migration with the circular dependency, but print a warning for the user?
comment:18 by , 4 weeks ago
We have adopted a (rather complex) process to produce dual level squashes. The guts of the idea is instead of squashing each app to a single migration we squash to two migrations. The first one creates all the tables, the second one creates all the FK's. This resolves all circularity issues.
follow-up: 20 comment:19 by , 4 weeks ago
OK, do you want to open a thread on the forum, pitch that idea to the community, and see what people think?
comment:20 by , 3 weeks ago
Replying to bcail:
OK, do you want to open a thread on the forum, pitch that idea to the community, and see what people think?
We're going to run it again in a few weeks, maybe after that. I will feel more comfortable sharing the scripts we use if we've just recently used them.
Test project