8

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)

user8802333
  • 469
  • 1
  • 8
  • 18

5 Answers5

4

I faced the same problem in django 2.2, The following worked for me...

  1. delete the migrations folder resided inside the app folder
  2. delete the pycache folder too
  3. restart the server [if your server is on and you are working from another cli]
  4. python manage.py makemigrations <app_name> zero
  5. python manage.py makemigrations <app_name> [explicit app_name is important]
  6. python manage.py migrate
MASBHA NOMAN
  • 145
  • 1
  • 11
3

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.

shivam singhal
  • 156
  • 4
  • 9
1
  1. w/in the app directory I deleted the pycache and migrations folders,

  2. from django.migrations tables I deleted all rows like this for PostgreSQL

    DELETE FROM public.django_migrations
    WHERE public.django_migrations.app = 'target_app_name';
    
  3. To delete any app tables already created for the tables to be created from scratch.

vpap
  • 1,389
  • 2
  • 21
  • 32
1

Mine didn't migrate cause there was already a record in the django_migrations table with the same name, so I just removed it and then migrate worked.

Axe
  • 11
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 27 '22 at 01:47
0

In my case my settings.py file had two entries for the DATABASES setting.

The first one being my postgres setting

DATABASES = {"default": env.db()}
DATABASE_URL = env("DATABASE_URL")

The second one being the default sqlite configuration.

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.sqlite3",
        "NAME": BASE_DIR / "db.sqlite3",
    }
}

It is worth checking that your setting file has only one DATABASE setting with the correct configuration.

firekhaya
  • 408
  • 1
  • 3
  • 8