[Django] #25749: Cannot use foreign keys between tables of the same non-default db

2 views
Skip to first unread message

Django

unread,
Nov 13, 2015, 2:44:29 AM11/13/15
to django-...@googlegroups.com
#25749: Cannot use foreign keys between tables of the same non-default db
-------------------------------+--------------------
Reporter: muraveill | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/25749>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 13, 2015, 2:45:48 AM11/13/15
to django-...@googlegroups.com
#25749: Cannot use foreign keys between tables of the same non-default db
-------------------------------------+-------------------------------------
Reporter: muraveill | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: foreign key | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by muraveill):

* needs_better_patch: => 0
* component: Uncategorized => Database layer (models, ORM)
* needs_tests: => 0
* keywords: => foreign key
* needs_docs: => 0
* type: Uncategorized => Bug


--
Ticket URL: <https://code.djangoproject.com/ticket/25749#comment:1>

Django

unread,
Nov 13, 2015, 2:46:33 AM11/13/15
to django-...@googlegroups.com
#25749: Cannot use foreign keys between tables of the same non-default db
-------------------------------------+-------------------------------------
Reporter: muraveill | Owner: nobody

Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: foreign key | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by muraveill):

* needs_docs: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/25749#comment:2>

Django

unread,
Nov 13, 2015, 3:59:01 AM11/13/15
to django-...@googlegroups.com
#25749: Cannot use foreign keys between tables of the same non-default db
-------------------------------------+-------------------------------------
Reporter: muraveill | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: foreign key | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by muraveill):

* status: new => closed
* resolution: => wontfix


--
Ticket URL: <https://code.djangoproject.com/ticket/25749#comment:3>

Reply all
Reply to author
Forward
0 new messages