#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.

-- 
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/050.4d7ccd3dc829930cc4283fc33de5f70b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to