Opened 8 years ago

Closed 8 years ago

#25749 closed Bug (wontfix)

Cannot use foreign keys between tables of the same non-default db

Reported by: muraveill Owned by: nobody
Component: Database layer (models, ORM) Version: 1.8
Severity: Normal Keywords: foreign key
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When one has multiple databases, one can use the using keyword (or a router class) to query or save entries to a specific db.
Cross-database references (foreign keys) are not supported, but nothing should prevent one from using references between tables of the _same_ db. But it does not work:

person = People(firstname=firstname, lastname=lastname)
person.save(using=MY_DB)

newuser = User(username=username, person=person)
newuser.save(using=MY_DB) # to illustrate, but it fails at the previous line

returns

Cannot assign "<People: People object>": "People" instance isn't saved in the database.

Using a router class telling models User and People to always use MY_DB, instead of the 'using' keyword, does not help.
At least there is a point missing in the documentation.

Change History (3)

comment:1 by muraveill, 8 years ago

Component: UncategorizedDatabase layer (models, ORM)
Keywords: foreign key added
Type: UncategorizedBug

comment:2 by muraveill, 8 years ago

Needs documentation: set

comment:3 by muraveill, 8 years ago

Resolution: wontfix
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top