4
我有兩個數據庫定義,default
這是一個普通的MySQL後端和redshift
(使用postgres
後端)。我想使用RedShift作爲僅用於django-sql-explorer的只讀數據庫。使用RedShift作爲額外的Django數據庫
這是我在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_*
表(並且由於postgres類型012而顯然失敗不被紅移支持:
...
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()'檢查是否存在遷移表,如果不存在,我相信會創建它。 –
嗯,好吧,我不能說我已經足夠好了。祝你好運。 –