使用Django在单独的postgres模式中执行迁移

问题描述

我有一个要求,我的Django项目需要与多个postgres模式连接。 例如:如果我们有20个数据库表,那么10个将保留在 public 模式中,其他10个将保留在 project_one 模式中。所有这些表都需要在2个独立的架构中分别使用django迁移创建。

在运行迁移的同时,我还需要向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',max_length=7,('household_registration_rate',models.FloatField(null=True,('t90_day_return_hhs',('t365_day_return_hhs',('created_at',models.DateTimeField(auto_Now_add=True)),('updated_at',models.DateTimeField(auto_Now=True)),],options={
                'db_table': 'benchmarks',}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)