Reputation: 983
Django keeps making duplicate migrations in for my application. I've ran makemigrations
and migrate
before I changed my model. After the changes I ran makemigrations
again to make migrations for the updated model, I got the following error:
CommandError: Conflicting migrations detected; multiple leaf nodes in the migration graph: (0001_initial, 0001_initial 3 in sessions; 0002_remove_content_type_name 3, 0002_remove_content_type_name, 0001_initial 3 in contenttypes; 0002_alter_permission_name_max_length 3, 0010_alter_group_name_max_length 3, 0007_alter_validators_add_error_messages 3, 0006_require_contenttypes_0002 3, 0005_alter_user_last_login_null 3, 0001_initial 3, 0008_alter_user_username_max_length 3, 0009_alter_user_last_name_max_length 3, 0011_update_proxy_permissions, 0011_update_proxy_permissions 3, 0004_alter_user_username_opts 3, 0003_alter_user_email_max_length 3 in auth; 0003_logentry_add_action_flag_choices 3, 0002_logentry_remove_auto_add 3, 0003_logentry_add_action_flag_choices, 0001_initial 3 in admin).
To fix them run 'python manage.py makemigrations --merge'
Running makemigrations --merge
doesn't work: ValueError: Could not find common ancestor of {'0002_remove_content_type_name', '0002_remove_content_type_name 3', '0001_initial 3'}
There are many duplicate migrations in apps that I haven't touched (auth, admin, etc.):
admin
[ ] 0001_initial 3
[X] 0001_initial
[ ] 0002_logentry_remove_auto_add 3
[X] 0002_logentry_remove_auto_add
[X] 0003_logentry_add_action_flag_choices
[ ] 0003_logentry_add_action_flag_choices 3
auth
[ ] 0001_initial 3
[X] 0001_initial
[ ] 0002_alter_permission_name_max_length 3
[X] 0002_alter_permission_name_max_length
[ ] 0003_alter_user_email_max_length 3
[X] 0003_alter_user_email_max_length
[ ] 0004_alter_user_username_opts 3
[X] 0004_alter_user_username_opts
[ ] 0005_alter_user_last_login_null 3
[X] 0005_alter_user_last_login_null
[ ] 0006_require_contenttypes_0002 3
[X] 0006_require_contenttypes_0002
[ ] 0007_alter_validators_add_error_messages 3
[X] 0007_alter_validators_add_error_messages
[ ] 0008_alter_user_username_max_length 3
[X] 0008_alter_user_username_max_length
[ ] 0009_alter_user_last_name_max_length 3
[X] 0009_alter_user_last_name_max_length
[ ] 0010_alter_group_name_max_length 3
[X] 0010_alter_group_name_max_length
[X] 0011_update_proxy_permissions
[ ] 0011_update_proxy_permissions 3
contenttypes
[ ] 0001_initial 3
[X] 0001_initial
[X] 0002_remove_content_type_name
[ ] 0002_remove_content_type_name 3
database
(no migrations)
sessions
[X] 0001_initial
[ ] 0001_initial 3
The only app that, as far as I know, should've been affected is database
. Why is Django making these duplicate migrations? Is there any way I can get rid of these? Or apply them so they are not blocking anymore? How I can make sure this doesn't happen again?
Upvotes: 1
Views: 4083
Reputation: 983
It turned out the duplicates weren't created by Django but by some other process. Completely removing my environment and reinstalling all dependencies helped. Removing the migrations also would've worked.
Upvotes: 1
Reputation: 19
Sometimes, if you have the option, the easiest and fastest way is...
or... if you have a db in production with data and you can't reset:
Important... copy /migrations/ folder somewhere to recover files if necessary.
Upvotes: 1