pythondjangomakemigrations

Django 2.2.4 - “No migrations to apply” when run migrate after makemigrations


I am trying to do a migration in django 2.2.4 in python 3.7. First I try to make do makemigations:

python3 manage.py makemigrations

I get:

Migrations for 'main':
  main/migrations/0001_initial.py
    - Create model TutorialCategory
    - Create model TutorialSeries
    - Create model Tutorial

But then I try the second step:

python3 manage.py migrate

I get:

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, main, sessions
Running migrations:
  No migrations to apply.

Even though a migration should happen.

I tried deleting my migrations folder and then remaking it (with the empty __init__.py file inside) but it still doesn't work.

(Note: I have been following along the tutorial: Linking models with Foreign Keys - Django Web Development with Python p.9 by sentdex)


Solution

  • Somehow your migrations are virtually or faked applied in the database, Truncating django_migrations table should work.

    1. Delete all the migrations files:

      find . -path "/migrations/.py" -not -name "init.py" -delete find . -path "/migrations/.pyc" -delete

    2. Truncate table:

      truncate django_migrations

    3. makemigrations, migrate.