i followed this solution to run customer django command programmatically , but it is limited for just one database connection. I have django app configured with multiple database , is it possible to run custom django command using specific database connection? exactly like when we use connections["DB_NAME_CONNECTION"].cursor() to execute an sql query thanks a lot for your help!
Asked
Active
Viewed 200 times
1 Answers
1
One option is to create a new settings module (here's a guide) that contains your specific database connection configuration, and then use that settings module when using call_command()
:
management.call_command('mycommand', '--settings=mysite.settings.specificconnection')

DJ Ramones
- 823
- 1
- 5
- 11
-
Thanks a lot ! that is the answer i need ! – farid Maghraoui Sep 30 '20 at 18:45