多数据库迁移

2024-10-03 13:23:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我在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

当我在postgre中打开新的\u postgre2(用于newpostgre)数据库时,我可以在那里看到我的Check1表。你知道吗

但是在我的postgre3(对于newpostgre2)数据库中,没有Check1表,只有那些初始迁移。你知道吗

迁移成功后,为什么在new\u postgre3中看不到我的表?你知道吗


Tags: djangoname数据库newdbpostgresqlpsycopg2engine
1条回答
网友
1楼 · 发布于 2024-10-03 13:23:56

因为同一个对象名可以在不同的模式中使用,所以有时会发生冲突。最佳实践允许许多用户使用一个数据库而不相互干扰。使用此更改第二个数据库用户并再次检查。我认为这是工作。你知道吗

'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': '',
},

Python管理.py迁移数据库=newpostgre2

相关问题 更多 >