Skip to content

Dynamic database foreign key to shared database fails #19

Description

@acknowledgeHim

DB: Mysql 8

Each client has on DB with all their necessary tables. Some tables reference foreign keys on a shared database table (not in the current client DB) but it fails with message saying that referenced table doesn't exist with the client DB but should be checking the shared DB.

Example:
client DB:
notes table = create table notes (id int, note varchar(255), assigned_by_id int, PRIMARY KEY(id), FOREIGN KEY assigned_by_id REFERENCES 'shared_db'.staff (id));

share DB:
staff table = create table staff(id int, name varchar(255), PRIMARY KEY(id));

Mysql throws error: 1146, "Table 'client_db.staff' doesn't exist" which is correct as it should be looking at the shared db. Below is the django statement that produces that error:

Notes.objects.all().values('id', 'assigned_by_id__name')

Is there someway to make it follow the Foreign Key to the other DB scheme?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions