在 MySQL 中,我们可以在不同数据库中的表之间建立外键关系。我发现很难在各自的 Django 模型上翻译这种关系。
我在文档中读到不支持跨数据库关系,但是我们可以覆盖一些属性/函数,以便我们可以将表标识为DB.table
而不是table
?
例如,在某些in 中引用了table table1
in 。Django 尝试(未成功)在 中查找,并引发了DB1
table2
DB2
table1
DB2
DatabaseError
Variable Value
charset 'latin1'
exc <class '_mysql_exceptions.ProgrammingError'>
self <MySQLdb.cursors.Cursor object at 0x2a87ed0>
args (195,)
db <weakproxy at 0x2a95208 to Connection at 0xdad0>
value ProgrammingError(1146, "Table 'DB2.table1' doesn't exist")
query 'SELECT (1) AS `a` FROM `table1` WHERE `table1`.`ndx` = 195 LIMIT 1'
除了方法之外,几乎所有东西都有效save
。朝着正确的方向推动会有很大帮助!