ycc
ycc

Reputation: 15

Django 'migration is applied before its dependency' when running any migration commands

I am using Django 3.0.2 that is connected to a local MySQL database.My project current has 2 apps, 'accounts' and 'home'.

I dropped all the tables in my database after updating some of my model fields and I removed all the files in the migrations folder except __init__.py. Trying to start the dev server shows an error: Dependency on app with no migrations: accounts, so I ran python manage.py makemigrations which returned this

Migrations for 'accounts':
  accounts\migrations\0001_initial.py
    - Create model User
Migrations for 'home':
  home\migrations\0001_initial.py
    - Create model Idea
    - Create model Reply

After this, running the server gives a warning saying

You have 1 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): accounts. Run 'python manage.py migrate' to apply them.

Doing so gives me an InconsistentMigrationHistory exception: Migration admin.0001_initial is applied before its dependency accounts.0001_initial on database 'default'


Running python manage.py showmigrations returns this:

accounts
 [ ] 0001_initial
admin
 [X] 0001_initial
 [X] 0002_logentry_remove_auto_add
 [X] 0003_logentry_add_action_flag_choices
auth
 [X] 0001_initial
 [X] 0002_alter_permission_name_max_length
 [X] 0003_alter_user_email_max_length
 [X] 0004_alter_user_username_opts
 [X] 0005_alter_user_last_login_null
 [X] 0006_require_contenttypes_0002
 [X] 0007_alter_validators_add_error_messages
 [X] 0008_alter_user_username_max_length
 [X] 0009_alter_user_last_name_max_length
 [X] 0010_alter_group_name_max_length
 [X] 0011_update_proxy_permissions
contenttypes
 [X] 0001_initial
 [X] 0002_remove_content_type_name
home
 [X] 0001_initial
sessions
 [X] 0001_initial

I've tried runing the commands in different orders but it eventually comes to the same result. I can provide more details about the app if needed.

Upvotes: 1

Views: 4920

Answers (1)

Sangam Jung Gauli
Sangam Jung Gauli

Reputation: 143

I hope you haven't cleared your model class. You can delete all files under migrations directory of your app directory excluding init.py file. You have to Drop table django_migrations. After you delete then run

python manage.py makemigrations account
python manage.py makemigrations home
python manage.py migrate

Upvotes: 1

Related Questions