Django向南迁移到不同的数据库

时间:2021-05-08 19:15:36

Does South honor database routers? I set up routers to route certain apps to one DB, and all other apps to the default DB. I even made sure that South migrationhistory table is in both DBs. But I can't get South to only apply migrations in the appropriate DB. I.e. even when I run south with --database, it applies all migrations to the database I specify, rather than just migrations from the app that should go to that DB.

南方荣誉数据库路由器吗?我设置路由器将某些应用程序路由到一个DB,所有其他应用程序路由到默认的DB。我甚至确保了South migrationhistory表在两个DBs中。但是我不能只在适当的DB中应用迁移。也就是说,即使当我运行south with -database时,它也会将所有迁移应用到我指定的数据库,而不是只从应用程序迁移到那个DB。

Help! Thanks.

的帮助!谢谢。

1 个解决方案

#1


10  

"Does South honor database routers?" No, it does not.

The problem is that Django's DB router routes queries to databases based on Apps/Models, whereas south is based on Tables. South really doesn't have much idea which model a table corresponds to (esp in the history). Andrew Godwin is currently working on a contrib module to django that will replace south and fix a lot of these problems, but right now you have to do a lot of this work manually using hacky methods (--database, .using()).

问题是Django的DB路由器基于应用程序/模型将查询路由到数据库,而south基于表。South并不知道一个表对应哪个模型(特别是历史上)。Andrew Godwin目前正在为django开发一个悔过书模块,该模块将替换south并修复许多此类问题,但是现在您必须使用hacky方法(—database, .using())手工完成大量此类工作。

I'd recomend for the sake of automation, having all tables exist in all databases and running all the migrations against all of those databases too. Just to make sure that all the constraints work consistently across all of the databases.

为了实现自动化,我将对所有数据库中都有所有表,并对所有这些数据库运行所有迁移。只是为了确保所有约束在所有数据库中一致地工作。

#1


10  

"Does South honor database routers?" No, it does not.

The problem is that Django's DB router routes queries to databases based on Apps/Models, whereas south is based on Tables. South really doesn't have much idea which model a table corresponds to (esp in the history). Andrew Godwin is currently working on a contrib module to django that will replace south and fix a lot of these problems, but right now you have to do a lot of this work manually using hacky methods (--database, .using()).

问题是Django的DB路由器基于应用程序/模型将查询路由到数据库,而south基于表。South并不知道一个表对应哪个模型(特别是历史上)。Andrew Godwin目前正在为django开发一个悔过书模块,该模块将替换south并修复许多此类问题,但是现在您必须使用hacky方法(—database, .using())手工完成大量此类工作。

I'd recomend for the sake of automation, having all tables exist in all databases and running all the migrations against all of those databases too. Just to make sure that all the constraints work consistently across all of the databases.

为了实现自动化,我将对所有数据库中都有所有表,并对所有这些数据库运行所有迁移。只是为了确保所有约束在所有数据库中一致地工作。