Reputation: 18228
Python Version 2.7 Django Version 1.9.7
I have created a Django app on heroku. I can't get the heroku server to migrate
properly. In the past I have done all the makemigrations
locally and then pushed them to the server. It has worked in the past. Now I thought I would choose to do the migrations all on the server side, since I am not running this app locally at all.
I just created one new model inside the models.py
for app 'main':
from __future__ import unicode_literals
from django.db import models
class InstagramPhotos(models.Model):
imageId = models.IntegerField()
userId = models.IntegerField()
likes = models.IntegerField()
captionText = models.CharField(max_length=200)
image = models.ImageField()
After pushing changes to the server, I ran this, with following output:
heroku run python manage.py makemigrations main
Running python manage.py makemigrations main on ⬢ glacial-beach-50253... up, run.8354 Migrations for 'main':
0001_initial.py: - Create model InstagramPhotos
Seems ok right? So then I try to migrate
which as you know will actually create the tables in the DB:
heroku run python manage.py migrate
Running python manage.py migrate on ⬢ glacial-beach-50253... up, run.7556 Operations to perform: Apply all migrations: auth, contenttypes, admin, sessions Running migrations: No migrations to apply. Your models have changes that are not yet reflected in a migration, and so won't be applied. Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
No matter how many times I have tried to re-run the makemigrations
and then migrate
it still seems to not pick it up. Not sure why this is happening besides it is just not possible to operate on heroku server this way? Do I definitely need to do makemigrations
locally and push?
FYI I just have the default sqlite3 DB still defined in settings.py
.
Upvotes: 16
Views: 25251
Reputation: 29
python manage.py makemigrations
python manage.py migrate
Commit your code
Push it to Heroku master
Run
heroku run python manage.py makemigrations
heroku run python manage.py migrate
Your issue should be resolved now.
Upvotes: 1
Reputation: 21
I struggled recently with a similar error and ended discovering that i mistakenly have been git ignoring init.py files. Without these files in the migrations folder, the migrate command cannot find the migration files and execute them.
Upvotes: 1
Reputation: 39
I ran into the same error two times while deploying to Heroku. While listing the files under the app directory, I found out db.sqlite3 file was missing which is necessary for django to create the sql tables. While it automatically creates the file in local, it wasn't getting created on the heroku while running migrate command.
There are two options from here:
Upvotes: 0
Reputation: 456
I had a similar problem.
I just ssh
into heroku dyno with:
heroku run bash
( from your heroku application folder ofc )
Than run all the migration and makemigration commands with createsuperuser if needed. Works with sqlite and postgre for me.
Upvotes: 28