3

I made syncdb (Python/Django application) in Heroku and he created table south_migrationhistory,

(venv-project)username@username:~/projectapp$ heroku run python manage.py syncdb
Running `python manage.py syncdb` attached to terminal... up, run.5529
Syncing...
Creating tables ...
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 django_site
Creating table django_admin_log
Creating table south_migrationhistory

(...)

Synced:
 > django.contrib.auth
 > django.contrib.contenttypes
 > django.contrib.sessions
 > django.contrib.sites
 > django.contrib.messages
 > django.contrib.staticfiles
 > django.contrib.admin
 > south

Not synced (use migrations):
 - core
 - galeria
(use ./manage.py migrate to migrate these)

but when I'll migrate application he says that table wasn't created:

(venv-project)username@username:~/projectapp$ heroku run python manage.py migrate core
Running `python manage.py migrate core` attached to terminal... up, run.7542

(...monstruous log...)

File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 337, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.DatabaseError: no such table: south_migrationhistory

What can be? Thanks.

EDIT: Solved, I put in settings_local gitignore and thereby recognized the database postgres heroku.

Filipe Manuel
  • 967
  • 2
  • 14
  • 33
  • 1
    did you try to run only migrate, no core? `heroku run python manage.py migrate` – catherine Mar 18 '13 at 03:12
  • @catherine I found the error. How I use two settings, one for the server and another location, I forgot to put the "local" in gitignore. Thus, the settings_local was put on a server running and was invalidating the postgres on Heroku. – Filipe Manuel Mar 19 '13 at 02:34
  • one for development and one for local? – catherine Mar 19 '13 at 03:02
  • @catherine Yes. In my "settings_local.py" I use sqlite3 and DEBUG=True, in "settings.py" I'm using dj-database-url, and others configs to database for Heroku – Filipe Manuel Mar 19 '13 at 03:45
  • Ok in your local_settings.py, just put only database – catherine Mar 19 '13 at 03:54

2 Answers2

6

Tested on Django 1.9

settings.py

in_heroku = False
if 'DATABASE_URL' in os.environ:
    in_heroku = True

import dj_database_url
if in_heroku:
    DATABASES = {'default': dj_database_url.config()}
else:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        }
    }

Then run:

heroku addons:create heroku-postgresql:hobby-dev
sudo apt-get intall postgresql libpq-dev
pip install dj-database-url psycopg2
pip freeze >requirements.txt
git add .
git commit -m 'msg'
git push heroku master
heroku run python manage.py migrate

References:

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
2

local_settings.py

import os

SITE_ROOT = os.path.dirname(__file__)

DEBUG = True
TEMPLATE_DEBUG = DEBUG

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

In your gitignore, add this:

project_name/local_settings.py
*.sqlite3
catherine
  • 22,492
  • 12
  • 61
  • 85