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

5

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)

Essie answered 28/8, 2019 at 19:11 Comment(2)
Is this all running locally? Not on Heroku, for example?Aggrade
Yes it is running all locally.Essie
D
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.

Dysphonia answered 28/8, 2019 at 19:41 Comment(3)
what is 'truncate django_migrations'?Folkmoot
@AlexM.M. truncate is delete all entrys on the table django_migrations.Goshorn
truncate django_migrations gives an error. truncate: you must specify either ‘--size’ or ‘--reference’ Try 'truncate --help' for more information.Merete
E
5

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
Ensile answered 7/4, 2020 at 13:19 Comment(2)
On the command: "python manage.py makemigrations <app_name> zero" What do this parameter 'zero' ?Goshorn
@ProgramadoresBrasil it just resets all migrationsEnsile
D
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.

Dysphonia answered 28/8, 2019 at 19:41 Comment(3)
what is 'truncate django_migrations'?Folkmoot
@AlexM.M. truncate is delete all entrys on the table django_migrations.Goshorn
truncate django_migrations gives an error. truncate: you must specify either ‘--size’ or ‘--reference’ Try 'truncate --help' for more information.Merete
S
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.

Sen answered 28/10, 2021 at 4:35 Comment(0)
L
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.

Lacunar answered 26/5, 2022 at 23:10 Comment(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.Unflinching
G
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.

Gantry answered 13/8, 2023 at 21:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.