#12540 closed Uncategorized (fixed)
Add support for cross-database foreign keys and m2m
Reported by: | Russell Keith-Magee | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.2-alpha |
Severity: | Normal | Keywords: | |
Cc: | Zbigniew Braniecki | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Django's multidb support currently prevents foreign keys from referencing foreign databases. This means the obvious use case of "put User objects in the auth database" et al are not possible.
The full solution requires at least the following:
- Modifying ForeignKey to relax foreign key constraints if it is known that the foreign key will be on another database
- Providing hooks to allow FK and M2M descriptors to look up the right database to use
There has been some initial discussion on django users about this subject.
Attachments (2)
Change History (11)
comment:1 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 15 years ago
Cc: | added |
---|
comment:3 by , 15 years ago
comment:4 by , 15 years ago
@zbraniecki: This is not a new idea - it has been made by several people over the history of multi-db development. Read up on the archives to see why it hasn't been added.
by , 15 years ago
Attachment: | t12540-r12262.1.diff added |
---|
First pass at improved cross-database support.
comment:5 by , 15 years ago
The patch I've just uploaded is a first pass at implementing a fix for cross-database support. Feedback is welcome.
by , 15 years ago
Attachment: | t12540-r12262.2.diff added |
---|
Version 2 of a fix for database allocation problems. This time with a public DB Router API.
comment:6 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:7 by , 11 years ago
Easy pickings: | unset |
---|---|
Severity: | → Normal |
Type: | → Uncategorized |
UI/UX: | unset |
The title/description of this ticket haven't actually been "fixed", have they? -- "Django doesn’t currently provide any support for foreign key or many-to-many relationships spanning multiple databases" -- https://docs.djangoproject.com/en/dev/topics/db/multi-db/#limitations-of-multiple-databases
Is the addition of such support still being considered, and tracked elsewhere?
comment:8 by , 11 years ago
I'm not aware of any plans to change the status quo here. Cross database referential integrity is a Hard Problem™. "Fixed" is perhaps misleading in this case, but it's as fixed as it's likely to get. The "fix" in this case was adding configurable routers, which lets you have a bit more control over where models are synchronised. That doesn't make cross database joins possible, but it does let you actively prevent them.
comment:9 by , 10 years ago
Any plans to extend this to make sharding possible? Or should I open a new ticket?
I suggest also adding config parameters that would bind apps in a project to a given database. Something like:
settings.py
DATABASES = {
}
INSTALLED_APPS = (
)
this would allow models to be able to discover that the ForeignKey referenced in app1.models is using db2. It would also allow for models in app1 to on save() add required records to models from app2 without having to explicitly use using() on them (which would constrain the app relations)
Does it sounds reasonable? Is it a material for a separate ticket?