2017-01-09 66 views
1

我把一切都建立在我的本地环境和Heroku的服务器上我的网站了代码,我只是有严重的麻烦架构迁移到PostgreSQL数据库上Heroku服务器。每当我试图heroku run python manage.py migrate,我得到以下(这将是一个初始迁移):故障迁移数据库模式的Heroku(Postgres的)

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 

这似乎不错,但然后使用heroku pg:info它告诉我,我有0表,进一步当我运行heroku run python manage.py showmigrations这就是我得到:

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 

所以看来,迁移不会通过,我想知道为什么是这样的话。该数据库是空的,我试着重置它,并再次尝试,但似乎没有任何工作。

编辑:下面是dj_database_url相关settings.py

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 
+0

如何你的数据库中定义?你在使用['dj-database-url'](https://github.com/kennethreitz/dj-database-url)吗? – Chris

+0

@Chris是的,我是 –

+0

你有什么local_settings?它是否覆盖数据库设置? –

回答

0

看起来从您的代码段,你加载你的dj_database_url CONFIGS在您尝试在本地设置带来。这就是问题。这里发生的是你的本地设置覆盖了生产设置(使用Postgres)。

当您运行迁移是发生了什么事:

  • Heroku的是创建一个新的本地SQLite数据库。
  • 在做迁移。
  • 说这是成功的。
  • 退出。

如果您将本地设置填充到db_database_url调用之上,那么事情应该开始对ya有神奇的效果!

+0

是的,你是对的。实际上,我最终将'settings.py'保持原样并从远程服务器上删除了'local_settings.py',它本来不应该被打开。这样,dev服务器仍然设置为'local_settings.py',但远程服务器不是。 –

+0

完美!这真棒= D – rdegges