Django 1.7 - "No Migrations to Apply" When Run Migrate After Makemigrations

Django 1.7 - No migrations to apply when run migrate after makemigrations

Sounds like your initial migration was faked because the table already existed (probably with an outdated schema):

https://docs.djangoproject.com/en/1.8/topics/migrations/#adding-migrations-to-apps

"This will make a new initial migration for your app. Now, when you
run migrate, Django will detect that you have an initial migration and
that the tables it wants to create already exist, and will mark the
migration as already applied
."

Otherwise you would get an no-such-table error :)

Did you clean up the applied-migrations table? That's also a common cause for non-applied migrations.

No migrations to apply' after Django migration

This worked for me;

python manage.py makemigrations --empty yourappname

python manage.py migrate yourappname

It turns out adding an extra empty migration forces django to recheck the table and in the process, it noticed the new migrations. There's probably some caching taking place somewhere.

Original answer

django migration No migrations to apply

Django keeps track of all the applied migrations in django_migrations table.
So just delete all the rows in the django_migrations table that are related to you app like:

DELETE FROM django_migrations WHERE app='your-app-name';

and then do:

python manage.py makemigrations
python manage.py migrate

Django Migration is not applying the migration changes

Deleting the migration directory is never a good idea, because Django then loses track of which migration has been applied and which not (and once an app is deployed somewhere it can become quite difficult to get things back in sync).

Disclaimer: whenever things like that occur it is best to backup the database if it contains anything valuable. If in early development it is not necessary, but once things on the backend get out of sync there is a chance of things getting worse. :-)


To recover, you could try resetting your models to match exactly what they were before you have added/removed the fields. Then you can run

$ python manage.py makemigrations myproj

which will lead to an initial migration (0001_initial...). Then you can tell Django to fake that migration, which means to tell it to set its internal counter to this 0001_initial:

With Django 1.7:

$ python manage.py migrate myproj

With Django >= 1.8:

$ python manage.py migrate myproj --fake-initial

Now, try to change your model and run makemigrations again. It should now create a 0002_foobar migration that you could run as expected.

django migrate No migrations to apply.

django keep records of current migrations log by table django_migrations in your db.

something like:
Sample Image

The migrations is a chain structure,it's depend on the parent node.By this table django can know which migrations file is executed.

In you case,no migrations to apply because the new create 0003_xxxx.py is record in this table,you can fix it by delete this record in this table.

If you want remove some migration file you need see Squashing migrations.

Heroku No migrations to apply

I'VE FINALLY FIXED IT!!! This is what I did:

First I did a backup Download by heroku pg:backups:restore capture

then heroku pg:backups:restore download
it made a "latest.dump" file

then I used heroku pg:reset
it deleted the recent database of host

then I applied my fixes on my models and forms
new fields has to have "defaults=None" for models with Data you want to preserve (If you won't do this, the merge for this model won't take effect and will be cancelled)

then I run heroku run bash
run python manage.py makemigrations appname
then migrate

and then used "pg_restore --verbose --clean --no-acl --no-owner -h yourDBhost -U yourDBuser -d yourDBname latest.dump" (Your database credentials will be found on your postgresql addon settings) and then type or copy-paste yourDBpassword(from credentials also) to merge the backed up database with the new one with changes

and know it's done and perfectly working!

Django-migrations in Django 1.7 detects model changes but does not apply them on migrate

The problem disappeared with generic project settings and reappeared with my old, complex project settings. I tracked the problem down to a database Router class that was missing an allow_migrate method.

DATABASE_ROUTERS = [ 'myproj.routers.DatabaseAppsRouter', ]

I use this router to handle queries for a separate app in the project (readonly/MySQL).

Sadly I can't blame anyone but myself, since the Django documentation states clearly:

Note that migrations will just silently not perform any operations on a model for which [allow_migrate] returns False. (link)

I had created this router some time ago and didn't add the allow_migrate method to my router class when I upgraded to Django 1.7. When I added the method and made sure it returned True when needed, migrations run and the problem is solved.

Django 1.7 - makemigrations not detecting changes

Ok, looks like I missed an obvious step, but posting this in case anyone else does the same.

When upgrading to 1.7, my models became unmanaged (managed = False) - I had them as True before but seems it got reverted.

Removing that line (To default to True) and then running makemigrations immediately made a migration module and now it's working. makemigrations will not work on unmanaged tables (Which is obvious in hindsight)



Related Topics



Leave a reply



Submit