Trouble getting Django set up on Heroku using South - keep getting ProgrammingError: relation does not exist

This is what I've been doing:

Locally - where I've got a brand new postgres database, and two files from two different apps:

python syncdb
python schemamigration api --initial
python schemamigration extapi --initial
python migrate api 0001 --fake
python migrate extapi 0001 --fake

This works swell, and I can add stuff to the database just fine.

Then, when pushing to Heroku, where I've already created an empty app:

git add .
git commit -m "Ready to go to Heroku"
git push heroku master
heroku run python syncdb

That outputs this:

Running `python syncdb` attached to terminal... up, run.9548
Creating tables ...
Creating table django_admin_log
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table south_migrationhistory

# create superuser prompt...
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)

 > django.contrib.admin
 > django.contrib.auth
 > django.contrib.contenttypes
 > django.contrib.sessions
 > django.contrib.messages
 > django.contrib.staticfiles
 > south
 > rest_framework

Not synced (use migrations):
 - api
 - extapi

Then I try to migrate those apps with heroku run python migrate and get this error:

Running `python migrate` attached to terminal... up, run.3724
Running migrations for api:
 - Migrating forwards to 0001_initial.
 > api:0001_initial
FATAL ERROR - The following SQL query failed: ALTER TABLE "api_song" ADD CONSTRAINT "summary_id_refs_id_36bb6e06" FOREIGN KEY ("summary_id") REFERENCES "extapi_summary" ("id") DEFERRABLE INITIALLY DEFERRED;
The error was: relation "extapi_summary" does not exist

Error in migration: api:0001_initial
Traceback (most recent call last):
  File "", line 10, in <module>
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/", line 399, in execute_from_command_line
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/", line 392, in execute
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/", line 285, in execute
    output = self.handle(*args, **options)
  File "/app/.heroku/python/lib/python2.7/site-packages/south/management/commands/", line 111, in handle
    ignore_ghosts = ignore_ghosts,
  File "/app/.heroku/python/lib/python2.7/site-packages/south/migration/", line 220, in migrate_app
    success = migrator.migrate_many(target, workplan, database)
  File "/app/.heroku/python/lib/python2.7/site-packages/south/migration/", line 254, in migrate_many
    result = migrator.__class__.migrate_many(migrator, target, migrations, database)
  File "/app/.heroku/python/lib/python2.7/site-packages/south/migration/", line 329, in migrate_many
    result = self.migrate(migration, database)
  File "/app/.heroku/python/lib/python2.7/site-packages/south/migration/", line 133, in migrate
    result =, database)
  File "/app/.heroku/python/lib/python2.7/site-packages/south/migration/", line 114, in run
    return self.run_migration(migration, database)
  File "/app/.heroku/python/lib/python2.7/site-packages/south/migration/", line 85, in run_migration
  File "/app/.heroku/python/lib/python2.7/site-packages/south/db/", line 318, in execute_deferred_sql
  File "/app/.heroku/python/lib/python2.7/site-packages/south/db/", line 282, in execute
    cursor.execute(sql, params)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/", line 53, in execute
    return self.cursor.execute(sql, params)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/", line 99, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/", line 53, in execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "extapi_summary" does not exist

To me, it looks like the tables just aren't even being created, but I have no idea why not. When I run heroku run python sqlall it says everything's been made, but then I look at the database itself (the one heroku makes on s3) there's nothing from app_one and app_two. Again, this all works perfect locally, it's just when it goes up on heroku that things fall apart.


There's a circular import that should've been handled by just deferring the creation of api_userprofile, but because of how South handles transactions, it breaks.

So! Easiest way to make this work is to get syncdb to make all the tables and just fake the migration:

python syncdb --all

That gets us:

 > django.contrib.admin
 > django.contrib.auth
 > django.contrib.contenttypes
 > django.contrib.sessions
 > django.contrib.messages
 > django.contrib.staticfiles
 > api
 > extapi
 > moodranker
 > recommender
 > south
 > rest_framework

Not synced (use migrations):

Then fake the migrations:

python migrate --fake

Delete your migrations folder and then do

python makemigrations appname

python migrate --run-syncdb

python migrate --fake appname

Need Your Help

Does a QTimer object run in a separate thread? What is its mechanism?

c++ multithreading qt timer qtimer

When I create a QTimer object in Qt 5, and start it using the start() member function, is a separate thread created that keeps track of the time and calls the timeout() function at regular interval...