django - 更改 django_migrations 架构
问题描述
有什么方法可以更改django_migrations
表的架构?我想将所有与 Django 相关的表移动到另一个名为 的模式django
,我已经使用过数据库路由器
class DjangoAppRouter:
route_app_labels = {'auth', 'contenttypes', 'admin'}
def db_for_read(self, model, **hints):
if model._meta.app_label in self.route_app_labels:
return 'django'
return None
def db_for_write(self, model, **hints):
if model._meta.app_label in self.route_app_labels:
return 'django'
return None
def allow_relation(self, obj1, obj2, **hints):
return True
def allow_migrate(self, db, app_label, model_name=None, **hints):
if app_label in self.route_app_labels:
return db == 'django'
return None
class PrimaryRouter:
def db_for_read(self, model, **hints):
return 'default'
def db_for_write(self, model, **hints):
return 'default'
def allow_relation(self, obj1, obj2, **hints):
return True
def allow_migrate(self, db, app_label, model_name=None, **hints):
return True
设置.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': ENV('DB_NAME'),
'USER': ENV('DB_USER'),
'PASSWORD': ENV('DB_PASS'),
'HOST': ENV('DB_HOST'),
'PORT': ENV.int('DB_PORT'),
},
'django': {
'ENGINE': 'django.db.backends.postgresql',
'OPTIONS': {
'options': '-c search_path=django'
},
'NAME': ENV('DB_NAME'),
'USER': ENV('DB_USER'),
'PASSWORD': ENV('DB_PASS'),
'HOST': ENV('DB_HOST'),
'PORT': ENV.int('DB_PORT'),
}
}
DATABASE_ROUTERS = ['bilikStudio.db-router.DjangoAppRouter', 'bilikStudio.db-router.PrimaryRouter']
但这不起作用django_migrations
。有什么建议么?使用此配置,它给了我这个错误:
django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table (no schema has been selected to create in
LINE 1: CREATE TABLE "django_migrations" ("id" serial NOT NULL PRIMA...
解决方案
推荐阅读
- ruby - 在对象初始化时在 ruby 中动态构建访问器
- visual-studio-2019 - 在 Visual Studio 2019 和 dotnetbrowser 中停止活动窗格穿透并激活其后面的对象的触摸手势
- android - 如何以编程方式实现谷歌位置自动完成并获得 kotlin 的 latlng?
- autodesk-forge - 如何强制设计自动化打开分离模型?
- java - Maven为python3 ANTLR语法文件生成python代码
- javascript - 使用反应钩子更改图像和描述 onClick 的最佳方法
- javascript - 使用 React 显示对象详细信息
- arrays - 使用 VBS 脚本在数组中添加和导出字符串
- flutter - 断开复选框 | 单独点击
- plotly - Plotly Map 绘制 lat-lng 点仅显示一天,而不是所有天