Opened 10 years ago

Last modified 4 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)

djtest.zip (5.0 KB ) - added by no 10 years ago.
Test project

Download all attachments as: .zip

Change History (21)

by no, 10 years ago

Attachment: djtest.zip added

Test project

comment:1 by Simon Charette, 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 no, 10 years ago

Version: 1.7-rc-21.7-rc-3

It was 1.7-rc-3, The option wasn't available when I reported.

comment:3 by Simon Charette, 10 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

Managed to reproduce.

comment:4 by Andrew Godwin, 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:5 by Andrew Godwin <andrew@…>, 10 years ago

In 459cfb523d8812081a623b29d0b8ab13bf87190a:

Update squashmigration docs to also mention circ dep errs (refs #23337)

comment:6 by Andrew Godwin, 10 years ago

Severity: Release blockerNormal
Version: 1.7-rc-3master

comment:7 by Andrew Godwin <andrew@…>, 10 years ago

In fbe45076234b1509a574a78a0f2b2dda602836db:

[1.7.x] Update squashmigration docs to also mention circ dep errs (refs #23337)

comment:8 by Markus Holtermann, 10 years ago

Cc: info+coding@… added

comment:9 by Ian Foote, 10 years ago

Cc: python@… added

comment:10 by Joey Wilhelm, 9 years ago

Cc: tarkatronic@… added

comment:11 by Sergey Fedoseev, 7 years ago

Cc: Sergey Fedoseev added

comment:12 by danniranderis, 6 years ago

Cc: danniranderis added

comment:13 by bcail, 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 bcail, 9 months ago

Cc: bcail added

comment:15 by Sarah Boyce, 7 months ago

#35463 is a duplicate

comment:16 by Gordon Wrigley, 7 months ago

Cc: Gordon Wrigley added

comment:17 by bcail, 5 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 Gordon Wrigley, 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.

comment:19 by bcail, 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?

in reply to:  19 comment:20 by Gordon Wrigley, 4 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.

Note: See TracTickets for help on using tickets.
Back to Top