I have everything set up in my local environment and the code for my website up on the Heroku server, I'm just having serious trouble getting the schema to migrate to the PostgreSQL database on the Heroku server. Whenever I attempt heroku run python manage.py migrate I get the following (this would be an initial migration):

    Running python manage.py migrate on baseballstatview... up, run.1653      (Free)
    Operations to perform:
    Apply all migrations: admin, auth, contenttypes, sessions, statview
    Running migrations:
      Applying contenttypes.0001_initial... OK
      Applying auth.0001_initial... OK
      Applying admin.0001_initial... OK
      Applying admin.0002_logentry_remove_auto_add... OK
      Applying contenttypes.0002_remove_content_type_name... OK
      Applying auth.0002_alter_permission_name_max_length... OK
      Applying auth.0003_alter_user_email_max_length... OK
      Applying auth.0004_alter_user_username_opts... OK
      Applying auth.0005_alter_user_last_login_null... OK
      Applying auth.0006_require_contenttypes_0002... OK
      Applying auth.0007_alter_validators_add_error_messages... OK
      Applying auth.0008_alter_user_username_max_length... OK
      Applying sessions.0001_initial... OK
      Applying statview.0001_initial... OK

Which seems fine but then using heroku pg:info it tells me I have 0 tables, and even further when I run heroku run python manage.py showmigrations this is what I get:

    Running python manage.py showmigrations on baseballstatview... up, run.5059 (Free)
    admin
     [ ] 0001_initial
     [ ] 0002_logentry_remove_auto_add
    auth
     [ ] 0001_initial
     [ ] 0002_alter_permission_name_max_length
     [ ] 0003_alter_user_email_max_length
     [ ] 0004_alter_user_username_opts
     [ ] 0005_alter_user_last_login_null
     [ ] 0006_require_contenttypes_0002
     [ ] 0007_alter_validators_add_error_messages
     [ ] 0008_alter_user_username_max_length
    contenttypes
     [ ] 0001_initial
     [ ] 0002_remove_content_type_name
    sessions
     [ ] 0001_initial
    statview
     [ ] 0001_initial

So it appears that the migrations are not going through and I'm wondering why that's the case. The database is empty, I've tried resetting it and trying again but nothing seems to work.

EDIT: below is the relevant settings.pyfor dj_database_url:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'mlb_data',
    'USER': 'postgres',
    'PASSWORD': 'pw',
    'HOST': 'localhost',
    'PORT': '5432',
 }
}

import dj_database_url

DATABASES['default'] = dj_database_url.config()

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

ALLOWED_HOSTS = ['*']

DEBUG = False

try:
    from .local_settings import *
except ImportError:
    pass
share|improve this question
    
How is your database defined? Are you using dj-database-url? – Chris Jan 9 at 21:15
    
@Chris yes I am – thumbtack_5 Jan 9 at 21:28
    
Do you have anything in local_settings? Does it override the database setting? – Daniel Roseman Jan 9 at 22:04
    
@thumbtack_5, and what is your DATABASE_URL environment variable on Heroku (make sure to sanitize it to remove the actual host, database name, user, and password)? I realize that's just about everything sanitized, but we need to see it. – Chris Jan 9 at 22:14
    
@DanielRoseman @Chris Thanks for both of your input. It does appear that my local_settings.py was over-riding settings.py – thumbtack_5 Jan 9 at 22:43

It looks from your code snippet that you are loading your dj_database_url configs BEFORE you attempt to bring in your local settings. This is the problem. What's happening here is that your local settings are overriding the production settings (with Postgres).

What's happening when you run the migration is:

  • Heroku is creating a new local SQLite database.
  • Doing the migrations.
  • Saying it's successful.
  • Exiting.

If you move that local settings stuff up above your db_database_url call, things should start magically working for ya!

share|improve this answer
    
Yup you're right. I actually ended up leaving settings.py as is and removed the local_settings.py from the remote server, which it should never have been on. That way the dev server is still set to local_settings.py but the remote is not. – thumbtack_5 Jan 11 at 22:17
    
Perfect! That's awesome =D – rdegges Jan 11 at 22:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.