【发布时间】:2017-04-15 02:25:35
【问题描述】:
我定义了两个数据库,default 是常规 MySQL 后端,redshift(使用 postgres 后端)。我想将 RedShift 用作只读数据库,仅用于django-sql-explorer。
这是我在my_project/common/routers.py创建的路由器:
class CustomRouter(object):
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):
db_list = ('default', )
if obj1._state.db in db_list and obj2._state.db in db_list:
return True
return None
def allow_migrate(self, db, app_label, model_name=None, **hints):
return db == 'default'
我的settings.py 是这样引用它的:
DATABASE_ROUTERS = ['my_project.common.routers.CustomRouter', ]
在调用makemigrations 时出现问题,Django 抛出一个错误,表明它正在尝试在 RedShift 中创建 django_* 表(显然由于 RedShift 不支持 postgres 类型 serial 而失败:
...
raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc)
django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table (Column "django_migrations.id" has unsupported type "serial".)
所以我的问题有两个:
- 是否可以完全禁用数据库的 Django 管理,但仍使用 ORM?
- 除了只读副本,为什么 Django 不认为它是支持只读数据库的可接受用例?
相关问题
-Column 'django_migrations.id' has unsupported type 'serial' [ with Amazon Redshift]
【问题讨论】:
-
@KevinChristopherHenry 我很确定它发生在
makemigrations脚本中,即使是在一个新项目中也是如此。在后端的执行调用中,ensure_backend()检查迁移表是否存在,如果不存在,我相信会创建它。
标签: python django postgresql orm amazon-redshift