首页 > 解决方案 > Django migration duplicate operation

问题描述

I'm using Django for the backend of my application and everything is fine except a little problem with my migrations.

I'm using a custom User model by inheriting from AbstractUser and I have something like the following :

class User(AbstractUser):

    class Meta:
        verbose_name = "User"

    # Fields and methods here
    # ...

which results in this part of the migration in my 0001_initial.py migration file :

options={
  'verbose_name': 'User',
  'verbose_name_plural': 'Users',
  'abstract': False,
},

The thing is, when I run makemigrations later on, it creates an automatic migration with this little part in it :

migrations.AlterModelOptions(
  name='user',
  options={'verbose_name': 'User'},
),

I do not understand why it tries to apply this modification a second time. Can someone help me ?

I could let it as it is but I try to keep my migration files as clean as possible.

Thanks in advance.

标签: djangodjango-migrations

解决方案


Well ! Since I haven't been able to understand what was going on, I decided to try deleting all the migrations (I'm not yet in production so I could !) and generate them back.

It ended up with this part for my User model :

options={
  'verbose_name': 'User',
},

Which is what I already had but...eh.

The good thing is that running makemigrations after that no longer generate weird things.


推荐阅读