As the title says, I can\'t seem to get migrations working.
The app was originally under 1.6, so I understand that migrations won\'t be there initially, and indeed i
People like me who don't like migrations can use steps below.
python manage.py makemigrations app_label
for the initial migration.python manage.py migrate
for creating tables before you make changes.If you confused any of these steps, read the migration files. Change them to correct your schema or remove unwanted files but don't forget to change next migration file's dependencies part ;)
I hope this will help someone in future.
I recently upgraded Django from 1.6 to 1.8 and had few apps and migrations for them. I used south and schemamigrations
for creating migrations in Django 1.6, which is dropped in Django 1.8.
When I added new models after upgrade, the makemigrations
command wasn't detecting any changes. And then I tried the solution suggested by @drojf (1st answer), it worked fine, but failed to apply fake initial migration (python manage.py --fake-initial
). I was doing this as my tables (old tables) were already created.
Finally this worked for me, removed new models (or model changes) from models.py and then had to delete (or rename for safety backup) migrations folder of all apps and run python manage.py
makemigrations for all apps, then did python manage.py migrate --fake-initial
. This worked like a charm. Once initial migration is created for all apps and fake initial migrated, then added new models and followed regular process of makemigrations
and migrate on that app. The changes were detected now and everything went fine.
I just thought of sharing it here, if someone faces same problem (having schemamigrations
of south for their apps), it might help them :)
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)
Adding my 2c, since none of these solutions worked for me, but this did...
I had just run manage.py squashmigrations
and removed the old migrations (both the files and lines in the the django.migrations database table).
This left a line like this in the last migration file:
replaces = [(b'my_app', '0006_auto_20170713_1735'), (b'my_app', '0007_auto_20170713_2003'), (b'my_app', '0008_auto_20170713_2004')]
This apparently confused Django and caused weird behavior: running manage.py makemigrations my_app
would recreate the initial migration as if none existed. Removing the replaces...
line fixed the problem!
If you're changing over from an existing app you made in django 1.6, then you need to do one pre-step (as I found out) listed in the documentation:
python manage.py makemigrations your_app_label
The documentation does not make it obvious that you need to add the app label to the command, as the first thing it tells you to do is python manage.py makemigrations
which will fail. The initial migration is done when you create your app in version 1.7, but if you came from 1.6 it wouldn't have been carried out. See the 'Adding migration to apps' in the documentation for more details.
First this solution is applicable to those who are facing the same issue during deployment on heroku server, I was facing same issue.
To deploy, there is a mandatory step which is to add django_heroku.settings(locals()) in settings.py file.
Changes: When I changed the above line to django_heroku.settings(locals(), databases=False), it worked flawlessly.