2017-01-09 45 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

相關問題