tortoise-orm icon indicating copy to clipboard operation
tortoise-orm copied to clipboard

doesn't identify anything when used multiple connections in config dict, also Model.save(using_db=) parameter not working

Open advenn opened this issue 3 years ago • 5 comments

Describe the bug In advance I should mention that I want to multi tenant app (same models for multiple databases) with tortoise. So in testing this actually work or not I created test project I wrote multiple connection params in config dict, wrote models, showed them in modules, in order to test I wrote insert data

To Reproduce I placed the code here https://dpaste.org/PMRx

Expected behavior It should save Model with, different databases BaseDBAsyncClient. and then get them get them with, but shows error : tortoise.exceptions.OperationalError: permission denied for table tournament

Additional context I saw NotImplemented areas inside tortoise-orm's source code. so what is the cause of error? how it can be solved? Is it even possible to create such app with tortoise?

advenn avatar Mar 25 '22 12:03 advenn

Check the permissions

long2ice avatar Mar 25 '22 12:03 long2ice

Check the permissions

long2ice avatar Mar 25 '22 12:03 long2ice

I created databases with postgres user, via createdb name;, as tortoise did not created schemas except default connection, I backuped the first tortoise made db and uploaded them to new db's with pg_dump, although all users are granted with all privileges respectively. Now I am trying to create only one user and many databases, and permit this to do anything to all databases

advenn avatar Mar 26 '22 06:03 advenn

I created databases with postgres user, via createdb name;, as tortoise did not created schemas except default connection, I backuped the first tortoise made db and uploaded them to new db's with pg_dump, although all users are granted with all privileges respectively. Now I am trying to create only one user and many databases, and permit this to do anything to all databases

when created one user and multiple databases, and granting all privileges over these databases it is working. but now there appeared another problem: how to use using_db=BaseDBAsyncClient in filtering data? now i trying to pk = await Model.save(using_db) after that I put these lines: added = await Model.filter(pk=pk, using_db=BaseDBAsyncClient it is not working, because filter doesn't take using_db parameter. so i need your help again. how can I get data from multiple databases?

advenn avatar Mar 26 '22 07:03 advenn

See https://tortoise.github.io/router.html

long2ice avatar Mar 26 '22 09:03 long2ice