Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"no such table" error on Heroku after django syncdb passed

I'm trying to deploy my Django application to Heroku. The migrations are in my local Git. When I try:

git push heroku master
heroku run python manage.py syncdb

It applies the migrations and also promts me to create superuser, which I successfully do. Now the application is up and running, however when I try to log into the Django admin it's throwing:

OperationalError no such table: user_user

When I try

heroku run python manage.py makemigrations    
heroku run python manage.py migrate
heroku run python manage.py createsuperuser

It applies all migrations, but fails to create superuser throwing:

django.db.utils.OperationalError: no such table: user_user

Either way I can not have my database set up and migrated on Heroku.

My database settings are:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

My user model is:

class User(AbstractUser):
    rating = models.PositiveIntegerField(default=settings.DEFAULT_USER_RATING)

Django version is 1.7.1.

How do I get my database tables created on Heroku?

like image 680
Vadim Tikanov Avatar asked Apr 21 '15 08:04

Vadim Tikanov


People also ask

Is Heroku good for Django?

If you are new to Django, please use Heroku because it is easy for you to deploy your Django project even you do not understand what is Nginx and Gunicorn.


1 Answers

You must not use sqlite3 on Heroku.

sqlite stores the database as a file on disk. But the filesystem in a Heroku dyno is not persistent, and is not shared between dynos. So, when you do heroku run python manage.py migrate, Heroku spins up a new dyno with a blank database, runs the migrations, then deletes the dyno and the database. The dyno that's running your site is unaffected, and never gets migrated.

You must use one of the Heroku database add-ons. There is a free tier for Postgres. You should use the dj-database-url library to set your database settings dynamically from the environment variables which Heroku sets.

Also, for the same reason, you must do manage.py makemigrations locally, commit the result to git, then push to Heroku.

like image 74
Daniel Roseman Avatar answered Oct 05 '22 17:10

Daniel Roseman