【发布时间】:2012-12-04 12:03:25
【问题描述】:
在 MySQL 中,我们可以在不同数据库中的表之间建立外键关系。我发现很难在各自的 Django 模型上翻译这种关系。
我在docs 中读到不支持跨数据库关系,但我们能否覆盖某些属性/函数,以便我们可以将表标识为DB.table 而不是table?
例如,DB1 中的表 table1 在 DB2 中的某些 table2 中被引用。 Django 尝试(未成功)在DB2 中找到table1,并引发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 方法外,几乎所有东西都可以工作。朝着正确的方向前进会有很大帮助!
【问题讨论】:
标签: django django-models django-admin foreign-key-relationship