[Django] #23121: Infinte migrations when changing Meta options

5 views
Skip to first unread message

Django

unread,
Jul 28, 2014, 11:05:03 AM7/28/14
to django-...@googlegroups.com
#23121: Infinte migrations when changing Meta options
----------------------------+----------------------
Reporter: JockeTF | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-rc-2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+----------------------
Changing a model's meta options sometimes causes Django to generate an
infinite number of migrations.

Create a model with meta options.

{{{#!python
from django.db import models

class Pony(models.Model):
date_created = models.DateTimeField()

class Meta():
ordering = ('-date_created',)
}}}

Make migrations.

{{{#!python
$ python3 manage.py makemigrations
Migrations for 'infinite':
0001_initial.py:
- Create model Pony
}}}

Remove the meta options from the model.

{{{#!python
from django.db import models

class Pony(models.Model):
date_created = models.DateTimeField()
}}}

Make migrations.

{{{#!python
$ python3 manage.py makemigrations
Migrations for 'infinite':
0002_auto_20140728_1440.py:
- Change Meta options on pony

$ python3 manage.py makemigrations
Migrations for 'infinite':
0003_auto_20140728_1440.py:
- Change Meta options on pony

$ python3 manage.py makemigrations
Migrations for 'infinite':
0004_auto_20140728_1440.py:
- Change Meta options on pony
}}}

I first encountered this issue when upgrading from Django 1.7b4 to 1.7c1.
I do not know what exactly is causing this, but it happens in more cases
than just when removing the meta options. In my project I have many
migrations scripts for several different models. Two of the models ended
up suffering from this issue after upgrading to Django 1.7c1. The issue is
still present in Django 1.7c2. Squashing the migrations does not help.
However, removing the migrations and starting anew solves the issue.

Below is an example of a squashed migration which suffers from this issue.

{{{#!python
from django.db import models, migrations

class Migration(migrations.Migration):

replaces = [('infinite', '0001_initial'), ('infinite',
'0002_auto_20140728_1440')]

dependencies = [
]

operations = [
migrations.CreateModel(
name='Pony',
fields=[
('id', models.AutoField(serialize=False,
auto_created=True, primary_key=True, verbose_name='ID')),
('date_created', models.DateTimeField()),
],
options={
'ordering': ('-date_created',),
},
bases=(models.Model,),
),
migrations.AlterModelOptions(
name='pony',
options={},
),
]
}}}

Starting from scratch solves the issue.

{{{#!python
from django.db import models, migrations

class Migration(migrations.Migration):

dependencies = [
]

operations = [
migrations.CreateModel(
name='Pony',
fields=[
('id', models.AutoField(primary_key=True, serialize=False,
auto_created=True, verbose_name='ID')),
('date_created', models.DateTimeField()),
],
options={
},
bases=(models.Model,),
),
]
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23121>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 28, 2014, 11:33:07 AM7/28/14
to django-...@googlegroups.com
#23121: Infinte migrations when changing Meta options
---------------------------------+------------------------------------

Reporter: JockeTF | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-rc-2
Severity: Release blocker | 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 timo):

* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* severity: Normal => Release blocker
* needs_tests: => 0
* needs_docs: => 0


Comment:

I can reproduce.

--
Ticket URL: <https://code.djangoproject.com/ticket/23121#comment:1>

Django

unread,
Jul 28, 2014, 1:48:27 PM7/28/14
to django-...@googlegroups.com
#23121: Infinte migrations when changing Meta options
---------------------------------+------------------------------------
Reporter: JockeTF | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.7-rc-2
Severity: Release blocker | Resolution: fixed

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 Andrew Godwin <andrew@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"d6e73a876d77e889efe839345d39690a7004e2f4"]:
{{{
#!CommitTicketReference repository=""
revision="d6e73a876d77e889efe839345d39690a7004e2f4"
Fixed #23121: AlterModelOptions operation not changing state right
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23121#comment:2>

Django

unread,
Jul 28, 2014, 1:48:54 PM7/28/14
to django-...@googlegroups.com
#23121: Infinte migrations when changing Meta options
---------------------------------+------------------------------------
Reporter: JockeTF | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.7-rc-2

Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by Andrew Godwin <andrew@…>):

In [changeset:"394053ce605a30c742d6270a80986b255adb3a30"]:
{{{
#!CommitTicketReference repository=""
revision="394053ce605a30c742d6270a80986b255adb3a30"
[1.7.x] Fixed #23121: AlterModelOptions operation not changing state right
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23121#comment:3>

Django

unread,
Jul 29, 2014, 3:45:35 AM7/29/14
to django-...@googlegroups.com
#23121: Infinte migrations when changing Meta options
---------------------------------+------------------------------------
Reporter: JockeTF | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.7-rc-2

Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by JockeTF):

Thank you! I can confirm that this solves the issue.

--
Ticket URL: <https://code.djangoproject.com/ticket/23121#comment:4>

Django

unread,
Sep 7, 2018, 1:18:10 PM9/7/18
to django-...@googlegroups.com
#23121: Infinte migrations when changing Meta options
---------------------------------+------------------------------------
Reporter: JockeTF | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.7-rc-2

Severity: Release blocker | Resolution: fixed
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 bacilla-ru):

* Attachment "migrations_bug.tar.gz" added.

test project

Django

unread,
Sep 7, 2018, 1:20:47 PM9/7/18
to django-...@googlegroups.com
#23121: Infinte migrations when changing Meta options
---------------------------------+------------------------------------

Reporter: JockeTF | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-rc-2
Severity: Release blocker | 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 bacilla-ru):

* status: closed => new
* resolution: fixed =>


Comment:

The same bug in version 2.1. Test project in attachment.

Migrations log:
{{{
$ python manage.py makemigrations app
Migrations for 'app':
app/migrations/0001_initial.py
- Create model TestEntity
$ python manage.py makemigrations app
Migrations for 'app':
app/migrations/0002_auto_20180907_1712.py
- Change Meta options on testentity
$ python manage.py makemigrations app
Migrations for 'app':
app/migrations/0003_auto_20180907_1713.py
- Change Meta options on testentity
$ python manage.py makemigrations app
Migrations for 'app':
app/migrations/0004_auto_20180907_1713.py
- Change Meta options on testentity
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23121#comment:5>

Django

unread,
Sep 7, 2018, 2:13:21 PM9/7/18
to django-...@googlegroups.com
#23121: Infinte migrations when changing Meta options
---------------------------------+------------------------------------

Reporter: JockeTF | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-rc-2
Severity: Release blocker | 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 bacilla-ru):

* Attachment "migrations_bug.tar.gz" added.

test project

--

Django

unread,
Sep 7, 2018, 2:28:07 PM9/7/18
to django-...@googlegroups.com
#23121: Infinte migrations when changing Meta options
---------------------------------+------------------------------------
Reporter: JockeTF | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.7-rc-2
Severity: Release blocker | Resolution: fixed

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 Simon Charette):

* status: new => closed
* resolution: => fixed


Comment:

Please open a new ticket instead of re-opening this closed one.

The issue you're encountering is due to a bug in a new feature in 2.0 that
allowed expressions to be used in `Model.Meta.ordering` (#26257) and has
little to do with this Django 1.7 era bug.

--
Ticket URL: <https://code.djangoproject.com/ticket/23121#comment:6>

Reply all
Reply to author
Forward
0 new messages