squashmigrations missing a simple optimization?

95 views
Skip to first unread message

Shai Berger

unread,
Sep 21, 2014, 2:00:06 PM9/21/14
to django-d...@googlegroups.com
Hi,

I'm looking into the details of migrations a little, and I ran into this
issue.

I have two migrations: The first creates a model, the second adds another
model and a field to the first model. I'd expect squashmigrations to patch the
AddField into the first CreateModel, but it finds "No optimizations possible".
What am I missing?

Thanks,
Shai.

===============
0001_initial.py
===============

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
]

operations = [
migrations.CreateModel(
name='Knight',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False,
auto_created=True, primary_key=True)),
('name', models.CharField(max_length=100)),
('of_the_round_table', models.BooleanField(default=None)),
],
options={
},
bases=(models.Model,),
),
]

==========================
0002_auto_20140920_1610.py
==========================

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
from django.conf import settings


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('tut', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='Quest',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False,
auto_created=True, primary_key=True)),
('name', models.CharField(max_length=100)),
('knights', models.ManyToManyField(to='tut.Knight')),
],
options={
},
bases=(models.Model,),
),
migrations.AddField(
model_name='knight',
name='owner',
field=models.ForeignKey(to=settings.AUTH_USER_MODEL, null=True),
preserve_default=True,
),
]

Shai Berger

unread,
Sep 22, 2014, 3:05:05 AM9/22/14
to django-d...@googlegroups.com
Replying to myself:

On Sunday 21 September 2014 20:59:46 Shai Berger wrote:
> Hi,
>
> I'm looking into the details of migrations a little, and I ran into this
> issue.
>
> I have two migrations: The first creates a model, the second adds another
> model and a field to the first model. I'd expect squashmigrations to patch
> the AddField into the first CreateModel, but it finds "No optimizations
> possible". What am I missing?
>

Yesterday-self is missing that foreign keys (seem to be) always added in
separate operations. This makes it easy to resolve reference loops.

Shai.
Reply all
Reply to author
Forward
0 new messages