'relation "django_admin_log" already exists

when i try to run python manage.py migrate i run into following error enter image description here

Upon running python manage.py run migrations it says no changes detected. and when i runserver it gives me warning that i have unapplied migrations as well.i have been searching internet for two hours but got not solution. Someone knowing the solution please share :)



Solution 1:[1]

The table in your database that stores migration data to keep track of what has been applied is out of date. Try running python manage.py migrate --fake

Solution 2:[2]

Don't Try This at Home

I faced this issue, i make two changes,

  1. change AUTH_USER_MODEL, so i have one migraiton about it
  2. second one add new field for my folder_model(migration name: folder_model 0021)

When my first migrate attempt(I already run makemigrations commands on local so i have migration files), it says;

django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency account.0001_initial on database 'default'

This error reiases because i change the AUTH_USER_MODEL in the middle of the project, normally you have to remove your database and fresh start from the beginnig(also truncate migrations etc.), according to Django doc -> https://code.djangoproject.com/ticket/25313

To fix this issue, you don't have to delete all migrations on db, just delete the migrations about admin(not from project just database) enter image description here

After that just run

python manage.py migrate

It throws relation "django_admin_log" already exists. For this issue, run:

python manage.py migrate --fake

That's it, but not completely. Make fake migration act like you already make your all migrations successfully and save these on db. The issue came here that i have another migration about folder_model 0021 and with fake migration it doesn't applied to my database table but saved to db_migrations table.

So fix this issue, delete the folder_model 0021to database migration table (just 0021 not all folder_model migrations).

After delete just run python manage.py migrate Everything is fine!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kevswanberg
Solution 2