Repetitve/Infinite migrations generated on ManyToManyField

39 views
Skip to first unread message

Marvin Mednick

unread,
Sep 26, 2016, 10:43:28 PM9/26/16
to Django users
I've the the following models related to a many-to-many relationship.   (Django 1.9.4  and sqlite)

Each time I run makemigrations, it generates an AlterField migration, which migrate successfully executes (no errors), but running makemigrations again will generate the identical migration.

Everything seems to be functional, but it shouldn't be doing this.  

Any guidance on what is causing this and ow to resolve or workaround this?

Classes:
class BugbaseFilter(models.Model):
    AND = 'AND'
    OR = 'OR'
    NONE = 'NONE'
    ASSOC_TYPE = (
        (AND,"AND of all items"),
        (OR,"OR of all items"),
        (NONE,"Single Item")
    )
    filterName = models.CharField(max_length=50)
    association = models.CharField(max_length=4,choices=ASSOC_TYPE,default=AND)


class BugbaseFilterItem(models.Model):
    fieldName   = models.CharField(max_length=100)
    checkValue = models.CharField(max_length=100)
    invert = models.BooleanField(default=False)
    regex = models.BooleanField(default=False)
    bugFilter = models.ManyToManyField(BugbaseFilter, related_name='items', related_query_name='item')
    alias = models.CharField(max_length=25, blank=True)

Migration generated:
class Migration(migrations.Migration):

    dependencies = [
        ('BugReporter', '0027_bugbasefilteritem_bugfilter'),
    ]

    operations = [
        migrations.AlterField(
            model_name='bugbasefilteritem',
            name='bugFilter',
            field=models.ManyToManyField(related_name='items', related_query_name='item', to='BugReporter.BugbaseFilter'),
        ),
    ]

The Table that is in my database looks like the following
CREATE TABLE "BugReporter_bugbasefilteritem_bugFilter" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "bugbasefilteritem_id" integer NOT NULL REFERENCES "BugReporter_bugbasefilteritem" ("id"), "bugbasefilter_id" integer NOT NULL REFERENCES "BugReporter_bugbasefilter" ("id"))


FYI... I've tried removing the related_name and related_query_item and doesn't make any difference.




Mike Dewhirst

unread,
Sep 26, 2016, 11:40:13 PM9/26/16
to django...@googlegroups.com
On 27/09/2016 6:58 AM, Marvin Mednick wrote:
> I've the the following models related to a many-to-many
> relationship.  (Django 1.9.4 and sqlite)
>
> Each time I run makemigrations, it generates an AlterField migration,
> which migrate successfully executes (no errors), but running
> makemigrations again will generate the identical migration.
>
> Everything seems to be functional, but it shouldn't be doing this. Â
>
> Any guidance on what is causing this and ow to resolve or workaround this?

Try declaring those constants outside the class. I think the migration
code sees things differently each time it looks.

>
> Classes:
> class BugbaseFilter(models.Model):
> Â Â Â AND = 'AND'
> Â Â Â OR = 'OR'
> Â Â Â NONE = 'NONE'
> Â Â Â ASSOC_TYPE = (
> Â Â Â Â Â Â Â (AND,"AND of all items"),
> Â Â Â Â Â Â Â (OR,"OR of all items"),
> Â Â Â Â Â Â Â (NONE,"Single Item")
> Â Â Â )
> Â Â Â filterName = models.CharField(max_length=50)
> Â Â Â association =
> models.CharField(max_length=4,choices=ASSOC_TYPE,default=AND)
>
>
> class BugbaseFilterItem(models.Model):
>    fieldName  = models.CharField(max_length=100)
> Â Â Â checkValue = models.CharField(max_length=100)
> Â Â Â invert = models.BooleanField(default=False)
> Â Â Â regex = models.BooleanField(default=False)
> Â Â Â bugFilter = models.ManyToManyField(BugbaseFilter,
> related_name='items', related_query_name='item')
> Â Â Â alias = models.CharField(max_length=25, blank=True)
>
> Migration generated:
> class Migration(migrations.Migration):
>
> Â Â Â dependencies = [
> Â Â Â Â Â Â Â ('BugReporter', '0027_bugbasefilteritem_bugfilter'),
> Â Â Â ]
>
> Â Â Â operations = [
> Â Â Â Â Â Â Â migrations.AlterField(
> Â Â Â Â Â Â Â Â Â Â Â model_name='bugbasefilteritem',
> Â Â Â Â Â Â Â Â Â Â Â name='bugFilter',
> Â Â Â Â Â Â Â Â Â Â Â
> field=models.ManyToManyField(related_name='items',
> related_query_name='item', to='BugReporter.BugbaseFilter'),
> Â Â Â Â Â Â Â ),
> Â Â Â ]
>
> The Table that is in my database looks like the following
> CREATE TABLE "BugReporter_bugbasefilteritem_bugFilter" ("id" integer
> NOT NULL PRIMARY KEY AUTOINCREMENT, "bugbasefilteritem_id" integer NOT
> NULL REFERENCES "BugReporter_bugbasefilteritem" ("id"),
> "bugbasefilter_id" integer NOT NULL REFERENCES
> "BugReporter_bugbasefilter" ("id"))
>
>
> FYI... I've tried removing the related_name and related_query_item and
> doesn't make any difference.
>
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/9944f984-22c9-41b0-b592-dcec2a950dd8%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/9944f984-22c9-41b0-b592-dcec2a950dd8%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Olivier Dalang

unread,
Oct 27, 2016, 12:03:52 PM10/27/16
to django...@googlegroups.com

Hi,

I noticed this behavior when changing the case of a app/model/field name. See if the name has the same case in the initial creation migration and in the model.

Cheers,

Olivier


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages