Is that possible to have model with foreign key fields on different databases? example:
class MultiBDModel(models.Model):
db1_user = models.ForeignKey(User) # here suppose to be foreign key on `db1`
db2_user = models.ForeignKey(User) # and here on `db2`
也许可以复制用户 。 应用自定义管理器 。 哪个返回查询设置为 = db1 。
在 sections. py
中:
DATABASES = {
default : {
ENGINE : django.db.backends.sqlite3 , # Add postgresql_psycopg2 , mysql , sqlite3 or oracle .
NAME : db1 , # Or path to database file if using sqlite3.
USER : , # Not used with sqlite3.
PASSWORD : , # Not used with sqlite3.
HOST : , # Set to empty string for localhost. Not used with sqlite3.
PORT : , # Set to empty string for default. Not used with sqlite3.
},
website : {
ENGINE : django.db.backends.sqlite3 , # Add postgresql_psycopg2 , postgresql , mysql , sqlite3 or oracle .
NAME : db2 , # Or path to database file if using sqlite3.
USER : , # Not used with sqlite3.
PASSWORD : , # Not used with sqlite3.
HOST : , # Set to empty string for localhost. Not used with sqlite3.
PORT : , # Set to empty string for default. Not used with sqlite3. # Set to empty string for default. Not used with sqlite3.
}
}