Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrations applied but no migration folder

Tags:

django

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:

  • I made the migrations (makemigrations then migrate) when I first deployed the project, and everything was ok. I didn't check that the migration folders were there though.
  • I didn't made any change to the database since this first migration and didn't remove any folder.

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:

  • How is it possible that the migrations were made, the tables were created, etc. but no migration folder was created ?
  • Where do I go from here ? I want to make the new migrations but almost all methods reinitializing migrations include the steps 'delete migrations folders'.
like image 492
Luci Avatar asked Sep 26 '17 08:09

Luci


1 Answers

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.

like image 193
knbk Avatar answered Sep 25 '22 18:09

knbk