Python 使用Django在单独的postgres模式中执行迁移
我有一个需求,我的Django项目需要与多个postgres模式连接。 例如:如果我们有20个DB表,那么10个将保留在public模式中,其他10个将保留在project\u one模式中。所有这些表都需要在两个单独的模式中分别使用django迁移创建 在运行迁移的同时,我还需要为Python 使用Django在单独的postgres模式中执行迁移,python,python-3.x,django,postgresql,database-schema,Python,Python 3.x,Django,Postgresql,Database Schema,我有一个需求,我的Django项目需要与多个postgres模式连接。 例如:如果我们有20个DB表,那么10个将保留在public模式中,其他10个将保留在project\u one模式中。所有这些表都需要在两个单独的模式中分别使用django迁移创建 在运行迁移的同时,我还需要为python manage.py migrate提供一些选项,以便只在那些特定的模式中创建表。或者可能是模型本身的一些设置 我们如何才能做到这一点 我的默认设置如下所示 DATABASES = { 'defa
python manage.py migrate
提供一些选项,以便只在那些特定的模式中创建表。或者可能是模型本身的一些设置
我们如何才能做到这一点
我的默认设置如下所示
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'HOST': 'localhost',
'NAME': 'schema_proj',
'USER': 'testing',
'PASSWORD': '',
'ATOMIC_REQUESTS': True,
}
}
在我的迁移文件中-
migrations.CreateModel(
name='Benchmarks',
fields=[
('uid', models.IntegerField(serialize=False, primary_key=True)),
('two_digit_desc', models.CharField(null=True, max_length=255, blank=True)),
('month_key', models.CharField(null=True, max_length=7, blank=True)),
('household_registration_rate', models.FloatField(null=True, blank=True)),
('t90_day_return_hhs', models.FloatField(null=True, blank=True)),
('t365_day_return_hhs', models.FloatField(null=True, blank=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
],
options={
'db_table': 'benchmarks',
}