Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django makemigrations and migrate on heroku server don't create tables

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.

like image 431
jeffery_the_wind Avatar asked Jul 12 '16 13:07

jeffery_the_wind


2 Answers

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.

like image 106
Dishant Chavda Avatar answered Oct 21 '22 13:10

Dishant Chavda


  1. Run these commands locally

python manage.py makemigrations,,, Python manage.py migrate

2.commit your code

3.push it to heroku master

  1. Run heroku run python manage.py makemigrations,,,, heroku run python manage.py migrate

Your issue should be solved

like image 30
anaco ndeda Avatar answered Oct 21 '22 14:10

anaco ndeda