Relation between different database?

32 views
Skip to first unread message

ANi

unread,
Sep 9, 2019, 11:54:28 PM9/9/19
to Django users
Hi, 

I have my asset table in local db which need to reference to the employee view from another database. 
But I realized that Django might not allow relations across databases, right?

so does it means that I can only store the employee key as string in the asset table?
or other way to achieve?

many thanks,
ANi

N'BE SORO

unread,
Sep 10, 2019, 1:55:25 AM9/10/19
to django...@googlegroups.com
Hello. 

Give me one example 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4cd4ea88-d6c1-42c5-92d2-f9a5b7f818d8%40googlegroups.com.

ANi

unread,
Sep 10, 2019, 2:00:40 AM9/10/19
to Django users
my real situation as an example.

local database
AssetModel(id, employee, name, barcode, location, value)

remote database
EmployeeView(id, name, department)

I am thinking to set employee in AssetModel as an ForeignKey which references to EmployeeView.
but it seems to be not allowed


N'BE SORO

unread,
Sep 10, 2019, 2:09:28 AM9/10/19
to django...@googlegroups.com
Ok you can add an additional column my_id and you give him the unique property = True

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

ANi

unread,
Sep 10, 2019, 2:31:01 AM9/10/19
to Django users
the key point is about the relation in different databases,
if it is possible to have relations, then I don't need to write additional code to access data from the remote one.


ANi於 2019年9月10日星期二 UTC+8上午11時54分28秒寫道:

Jason

unread,
Sep 10, 2019, 6:32:22 AM9/10/19
to Django users
https://docs.djangoproject.com/en/2.2/topics/db/multi-db/

If you have to do this, Django does support multiple databases. But you’re going to need to handle the data consistency and integrity you’r.
Message has been deleted

ANi

unread,
Sep 10, 2019, 9:16:26 PM9/10/19
to Django users
Thanks, Jason.

I was trying to connect a table to a view from another database.
But it is not allowed to have a foreign key on a view unless I use a materialized view! 
Problem is solved. 




ANi於 2019年9月10日星期二 UTC+8上午11時54分28秒寫道:

Most. Runa

unread,
Sep 11, 2019, 11:58:05 AM9/11/19
to django...@googlegroups.com
Now i am full sexul mood guys coming my puss kiss 

On Wed, 11 Sep 2019, 6:51 a.m. ANi, <afji...@gmail.com> wrote:
Thanks, Jason.
Then another question, actually why I am asking this is because I am using django-export-import, 
I think it is better to have another title.

This is my router, I've set the foreignkey between A Model from default database and EmpAXView from emp database.
django-export-import tells me this:
no such table: main.View_EmpAX
or the relation is not allowed.

so I am thinking it is the problem of allow_relation method. but I don't get the concept about how to write it..........

擷取.PNG



ANi於 2019年9月10日星期二 UTC+8上午11時54分28秒寫道:
ANi於 2019年9月10日星期二 UTC+8上午11時54分28秒寫道:

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages