django.db.migrations.exceptions.InconsistenMigrationHistory

Hi, I have recently deleted the directory for an application that I created in Django.

I created the application within an exisitng Django project folder using the following command: python manage.py startapp app_name

I then deleted the name of the directory for app_name.

After creating a new application using python manage.py runserver startapp new_app, I attempted to make migrations with either python manage.py makemigrations or python manage.py migrate, I receive the following error message in the terminal:

raise InconsistentMigrationHistory(
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration ExamQuestions.0001_initial is applied before its dependency Exams.0001_initial on database ‘default’.

I am attaching an image of the error message and will appreciate any advice regarding this. Thank you.

If you deleted that directory and everything under it (including the migrations directory), your best bet is to drop the database, delete all migrations from your apps and rebuild the database from scratch.

Suggestion for the future - don’t delete files (or directories) without understanding how that’s going to affect the rest of your project.
Yes, it’s possible to delete Django apps, but it takes more than just deleting a directory to do it cleanly. You should also be aware of how doing something like that might affect an existing installation and your options for upgrading a running system.

You say that I should drop the database.

My question is where is this database located? Within the main directory of the Django project?

It’s located where it is defined in your DATABASES setting. If it’s a sqlite database, then yes, it’s probably easiest just to delete that file. If it’s a PostgreSQL or MySQL/MariaDB database, you would want to drop the database itself.

Thank you Mr. Whitesell! It worked!