Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#27038 closed Bug (needsinfo)

Migration being created even when no change was made.

Reported by: Ricardo Serrano Owned by: nobody
Component: Migrations Version: 1.9
Severity: Normal Keywords: makemigrations
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I'm having a problem with migrations. They are being created by makemigrations even after no change has been made. I'm in my 57th migration so I can't create a simple way to reproduce the problem.

My model is this:

class Layer3d(Process):
    last_modified = models.DateTimeField(auto_now=True)
    info          = models.TextField(verbose_name=_('layer info'), default='{}')

class Layer3dProjection(models.Model, Layer3dProjectionMixin):
    name     = models.CharField(verbose_name=_('name'), max_length=40, default='', validators=[name_regex], unique=True)
    llist    = models.ForeignKey(LayerList, verbose_name=_('layer list'))
    layer3d  = models.ForeignKey(Layer3d)
    distance = models.FloatField(default=-1)
    last_modified = models.DateTimeField(auto_now=True)
    
    class Meta:
        unique_together = (('llist', 'name'),)
        ordering = ['name']

This migration is being created, time after time, without modifying any model.

# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-08-09 00:50
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion

The migration being created is this.

class Migration(migrations.Migration):

    dependencies = [
        ('studies', '0057_auto_20160809_0047'),
    ]

    operations = [
        migrations.AlterField(
            model_name='layer3dprojection',
            name='layer3d',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='studies.Layer3d'),
        ),
    ]

Change History (8)

comment:1 by Tim Graham, 8 years ago

Can you try minimizing the model to see what you can remove while still reproducing the issue? Not sure it's relevant, but Python 2 or 3?

comment:2 by Ricardo Serrano, 8 years ago

I can't. I have 57 migrations total. I made the changes, tried to change the fields but to no avail. I even tried to squash the migrations but same problem. I haven't seen the problem before, I don't know how it occurred, but it occurs consistently.

comment:3 by Claude Paroz, 8 years ago

Could you at least find the previous CreateField/AlterField for this field in the previous migrations? This would help us find what part of the field is triggering the change (name, on_delete, to, ...). Without further information, it's not possible for us to debug this.

comment:4 by Tim Graham, 8 years ago

Resolution: needsinfo
Status: newclosed

comment:5 by Ricardo Serrano, 8 years ago

Of course. This is the squashed migration.

# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-08-09 00:17
from __future__ import unicode_literals

import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import studies.model_mixins


class Migration(migrations.Migration):

    replaces = [(b'studies', '0055_auto_20160713_1637'), (b'studies', '0056_auto_20160713_2229'), (b'studies', '0057_auto_20160714_2357'), (b'studies', '0058_auto_20160728_2032'), (b'studies', '0059_auto_20160801_2020'), (b'studies', '0060_auto_20160805_1655'), (b'studies', '0061_auto_20160808_2135')]

    dependencies = [
        ('studies', '0054_auto_20160711_0144'),
    ]

    operations = [

        migrations.CreateModel(
            name='Layer3D',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('last_modified', models.DateTimeField(auto_now=True)),
                ('info', models.TextField(default=b'{}', verbose_name='layer info')),
            ],
            options={
                'ordering': ['name'],
            },
        ),
        migrations.CreateModel(
            name='Layer3dProjection',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(default=b'', max_length=40, unique=True, validators=[django.core.validators.RegexValidator(message='Name should only contain letters, numbers, spaces, underscores and dots.', regex=b"^[A-Za-z0-9][A-Za-z0-9' _\\.-]*[A-Za-z0-9']$")], verbose_name='name')),
                ('distance', models.FloatField(default=-1, verbose_name='distance to search lines')),
                ('last_modified', models.DateTimeField(auto_now=True)),
                ('layer3d', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='studies.Layer3d', verbose_name='layer3d to project')),
                ('llist', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='studies.LayerList', verbose_name='layer list')),
            ],
            options={
                'ordering': ['name'],
            },
            bases=(models.Model, studies.model_mixins.Layer3dProjectionMixin),
        ),
        migrations.AlterUniqueTogether(
            name='layer3dprojection',
            unique_together=set([('llist', 'name')]),
        ),
    ]

Sorry I had not seen the reply.

comment:6 by Ricardo Serrano, 8 years ago

Well, if you are going to close it at least tell me how to debug it. How do I know why is it finding differences between the models? Everything else works fine, those fields work fine.

comment:7 by Tim Graham, 8 years ago

Take look at django/db/migrations/autodetector.py's generate_altered_fields() method and see how old_field_dec and new_field_dec differ.

comment:8 by Simon Charette, 8 years ago

It looks like it might have something to do with the field's verbose_name.

Note: See TracTickets for help on using tickets.
Back to Top