django - Heroku 创建了表,但是当我要迁移时,他说没有创建

标签 django deployment heroku

我在Heroku中创建了syncdb(Python/Django应用程序),他创建了表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)

但是当我迁移应用程序时,他说该表未创建:

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

(...可怕的日志...)

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

可以是什么?谢谢。

编辑: 解决了,我放入settings_local gitignore,从而识别出数据库postgres heroku。

最佳答案

在 Django 1.9 上测试

设置.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'),
        }
    }

然后运行:

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

引用文献:

关于django - Heroku 创建了表,但是当我要迁移时,他说没有创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15467389/

相关文章:

mysql - 以md5格式保存md5密码django?

python - 使用抽象类对多对多关系建模

java - Tomcat - 当应用程序未正确部署时如何获取 http 500 而不是 404?

java - 将 war 部署到 JBoss AS 7 时出错(域模式): "Failed to process phase STRUCTURE of deployment"

.net - SetUp.exe 文件对于部署包来说是唯一的吗?

python - NoReverseMatch 位于/accounts/detail

django - 在 ec2 中自动部署

ruby-on-rails - 在 Heroku 上降级到免费 dyno 后出现 SSL 错误

mysql - heroku rails 应用程序 :test RDS mysql as suggested by Heroku June 2016 article?

ruby - 瘦服务器多次记录同一个请求