2017-02-27 95 views
0

我在我的django應用程序中使用了2個postgres數據庫。多個數據庫 - 遷移

'newpostgre': { 
    'ENGINE': 'django.db.backends.postgresql_psycopg2', 
    'NAME': 'new_postgre2', 
    'USER': 'tester', 
    'PASSWORD': 'password', 
    'HOST': 'localhost', 
    'PORT': '', 
}, 
'newpostgre2': { 
    'ENGINE': 'django.db.backends.postgresql_psycopg2', 
    'NAME': 'new_postgre3', 
    'USER': 'tester', 
    'PASSWORD': 'password', 
    'HOST': 'localhost', 
    'PORT': '', 
}, 

我有一個非常簡單的模型

class Check1(models.Model): 
     title = models.CharField(max_length=100) 

我已經跑

python manage.py migrate --database=newpostgre 
python manage.py migrate --database=newpostgre2 
當我睜開new_postgre2(用於newpostgre)在postgre數據庫

,我可以看到我的檢查1桌上有。

但是在我的postgre的new_postgre3(for newpostgre2)數據庫中,沒有Check1表存在,只有那些最初的遷移。

爲什麼我在遷移成功後無法在new_postgre3中看到我的表?

+0

您是否使用DB路由器? – itzMEonTV

回答

0

因爲相同的對象名稱可以在不同的模式中使用有時會發生衝突。最佳實踐允許許多用戶使用一個數據庫而不會相互干擾。使用此更改第二個數據庫用戶並再次檢查。我認爲這是工作。

'newpostgre': { 
    'ENGINE': 'django.db.backends.postgresql_psycopg2', 
    'NAME': 'new_postgre2', 
    'USER': 'tester', 
    'PASSWORD': 'password', 
    'HOST': 'localhost', 
    'PORT': '', 
}, 
'newpostgre2': { 
    'ENGINE': 'django.db.backends.postgresql_psycopg2', 
    'NAME': 'new_postgre3', 
    'USER': 'tester_different', 
    'PASSWORD': 'password_different', 
    'HOST': 'localhost', 
    'PORT': '', 
}, 

蟒蛇manage.py遷移--database = newpostgre2

+0

抱歉兄弟,但那也不起作用,儘管你的努力。我再次檢查數據庫,現在用不同的用戶,但是再次默認進行遷移,但模型不存在。 – Luv33preet