Dan*_*men 6 python django postgresql orm amazon-redshift
我定义了两个数据库,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'
Run Code Online (Sandbox Code Playgroud)
我的settings.py
引用如下:
DATABASE_ROUTERS = ['my_project.common.routers.CustomRouter', ]
Run Code Online (Sandbox Code Playgroud)
调用时出现问题makemigrations
,Django抛出一个错误,表明它正在尝试django_*
在RedShift中创建表(并且由于serial
RedShift不支持postgres类型,显然失败了:
...
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".)
Run Code Online (Sandbox Code Playgroud)
所以我的问题是双重的:
相关问题
- 列'django_migrations.id'具有不受支持的类型'serial'[与Amazon Redshift]
我刚刚发现这是一个bug的结果.它已在一些PR中得到解决,最值得注意的是:https://github.com/django/django/pull/7194
那么,回答我自己的问题:
allow_migrate()
返回False
. 归档时间: |
|
查看次数: |
723 次 |
最近记录: |