Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different databases with the same models on Django

I have the following issue:

I need a different database with the same models for each user (or set of users). I have a way of finding out to which database the user is related. The issue is I always have to use the using method on every query I make.

For example:

Thing.objects.using('appropriate_database').all()

Is there a way to avoid the use of using and making the user/database relationship implicit somehow?

like image 690
Bonifacio2 Avatar asked Dec 15 '25 16:12

Bonifacio2


1 Answers

Sounds like a bad design that can't scale to me. You have to duplicate the schema every time you add a user.

A better design would have a table USER with one-to-many and many-to-many relations with entities required by each user.

like image 123
duffymo Avatar answered Dec 17 '25 07:12

duffymo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!