#24849: Broken squashmigration when model related to another one gets deleted
----------------------------+------------------------------------
Reporter: riklaunim | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------------------
Changes (by timgraham):
* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0
Comment:
I had to add `related_name` in step two to avoid a clashing accessor error
from the system check error. With that, when I tried to reproduce this, I
got the following squashed migration:
{{{
operations = [
migrations.CreateModel(
name='News',
fields=[
('id', models.AutoField(primary_key=True, serialize=False,
auto_created=True, verbose_name='ID')),
('title', models.CharField(max_length=100)),
('category', models.ForeignKey(blank=True, null=True,
to='squash.NewCategory', related_name='foo')),
],
),
migrations.CreateModel(
name='NewCategory',
fields=[
('id', models.AutoField(primary_key=True, serialize=False,
auto_created=True, verbose_name='ID')),
('title', models.CharField(max_length=100)),
],
),
migrations.AddField(
model_name='news',
name='new_category',
field=models.ForeignKey(blank=True, null=True,
to='squash.NewCategory'),
),
migrations.RemoveField(
model_name='news',
name='category',
),
]
}}}
This has the problem that `NewCategory` is created after it's used in the
`ForeignKey` which results in `ValueError: Related model
'squash.NewCategory' cannot be resolved` when migrating. Accepting at
least on that basis.
--
Ticket URL: <https://code.djangoproject.com/ticket/24849#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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.2b2bf2723a0782e5890990bc00010689%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.