Opened 8 years ago
Last modified 8 years ago
#27319 new Bug
Circular ForeignKeys between two unmanaged models produce incomplete migrations
Reported by: | Jamie Bliss | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 1.10 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Pull Requests: | How to create a pull request | ||
Description ¶
From what I understand, makemigrations
produces migrations for unmanaged models, and the state of those migrations are tracked, but no SQL is actually run.
The way that makemigrations
handles circular ForeignKey
references between two models is to produce two migrations. (This may only happen if the two models are in different applications.)
However, when both the models involved are unmanaged (managed = False
), the second migration is not produced, leaving the migrations overall inconsistent with the models (and therefore, useless).
The workaround appears to be temporarily removing the managed flag, running the migrations, restoring the managed flag on the models and manually inserting it into the migrations.
According to the ticket's flags, the next step(s) to move this issue forward are:
- To provide a patch by sending a pull request. Claim the ticket when you start working so that someone else doesn't duplicate effort. Before sending a pull request, review your work against the patch review checklist. Check the "Has patch" flag on the ticket after sending a pull request and include a link to the pull request in the ticket comment when making that update. The usual format is:
[https://github.com/django/django/pull/#### PR]
.
Change History (3)
follow-up: 2 comment:1 by , 8 years ago
comment:2 by , 8 years ago
Replying to Tim Graham:
Just to be sure the ticket isn't interpreted incorrectly, could you provide the sample models?
In a new project, I started the apps app1
and app2
and added them to INSTALLED_APPS
.
app1/models.py
:
from django.db import models class Spam(models.Model): myegg = models.ForeignKey('app2.Egg') class Meta: managed = False
app2/models.py
:
from django.db import models class Egg(models.Model): myspam = models.ForeignKey('app1.Spam') class Meta: managed = False
In my case, only one migration in each application was created, and neither myegg
nor myspam
appears in either, just the primary keys.
comment:3 by , 8 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Uncategorized → Bug |
Thanks, I can reproduce the issue and I guess it's a bug. Probably not very high priority since circular foreign keys are an usual design.
Just to be sure the ticket isn't interpreted incorrectly, could you provide the sample models?