I have a django model which i would call as base model. I have created a project which dynamically creates new databases. Now, i found that i have to make a change to a table schema in the base table. How do i update this change to all the created databases?.
Asked
Active
Viewed 123 times
1
-
2"I have created a project which dynamically creates new databases" - stop right there. Delete it. – Daniel Roseman Feb 27 '12 at 10:45
-
I meant new databases. I have a base database. For each tenant , my project creates a new database by using sync db command. My app is in production now and now i have realized that i have to update a table schema in all the created databases. – kirans_6891 Feb 27 '12 at 10:54
-
Telling the truth it's a problem to create new databases with Django if you would like to use them from one project (may be other databases are only static copies?). If do then all your databases must be listed in DATABASES dict. But changing dynamically DATABASES dict is not good style of programming. – sergzach Feb 27 '12 at 11:10
2 Answers
1
May be it's not a real decision of your current problem but the decision of future problems: do schema changes in all databases at one time.
You could automate the process. Do the next for all databases in a loop:
from subprocess import call
# get names of your databases in list 'databases' here
for database in databases:
call( "python ./manage.py syncdb --database={0}".format( database ) )

sergzach
- 6,578
- 7
- 46
- 84
-
This is what i was looking for. Thanks.. Let me test it out by creating a new command and using the above code for the command. – kirans_6891 Feb 27 '12 at 11:07
0

Mariusz Jamro
- 30,615
- 24
- 120
- 162
-
./manage.py evolve --hint --execute will update a single database with reference to the model. I have to update multiple databases. – kirans_6891 Feb 27 '12 at 10:55