多个数据库 - 迁移
问题描述:
我在我的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中看到我的表?
答
因为相同的对象名称可以在不同的模式中使用有时会发生冲突。最佳实践允许许多用户使用一个数据库而不会相互干扰。使用此更改第二个数据库用户并再次检查。我认为这是工作。
'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
您是否使用DB路由器? – itzMEonTV