Luci
Luci

Reputation: 477

Migrations applied but no migration folder

I have developed a Django 1.8 project a while ago. I deployed the project a few months back and everything was running perfectly. Today, I had to make a change in the database, but when I tried to run python manage.py makemigrations, I got the message "No changes detected". I then noticed that there was no migration folder in any of the apps of the project. What I don't understand is:

When I run python manage.py showmigrations, I get the following:

admin
 [X] 0001_initial
auth
 [X] 0001_initial
 [X] 0002_alter_permission_name_max_length
 [X] 0003_alter_user_email_max_length
 [X] 0004_alter_user_username_opts
 [X] 0005_alter_user_last_login_null
 [X] 0006_require_contenttypes_0002
contenttypes
 [X] 0001_initial
 [X] 0002_remove_content_type_name
sessions
 [X] 0001_initial

This is the full output. No sign of any of my apps.

So my questions are the following:

Upvotes: 10

Views: 11998

Answers (1)

knbk
knbk

Reputation: 53679

Apps are allowed to have no migrations. Only apps with a migrations/__init__.py file are considered to have migrations. manage.py makemigrations won't create migrations for unmigrated apps unless you explicitly pass the app name. On Django 1.7/1.8, the tables are still created automatically through the old syncdb mechanism -- starting on Django 1.9, this requires the --syncdb flag when migrating.

Now you need to get your migrations in sync with your database. For this, you need to:

  1. Revert all model changes you made after initially running manage.py migrate.
  2. Run manage.py makemigrations <app_label> to create an initial migration that matches your current database.
  3. Run manage.py migrate --fake-initial <app_label> to mark the new migration as applied.

After running these steps for each app your migrations should be in sync with your database, so you can now edit your models and create new migrations.

Upvotes: 22

Related Questions