How to create or add multiple databases in django. Where always my models are created in default database .how to change it
Asked
Active
Viewed 60 times
0
-
Please post what you have tried. – Xcoder Nov 24 '18 at 16:43
-
I dint tried any. I'm blank in switching dbs – Gamer Nov 24 '18 at 17:23
-
Have you tried [Google searching](https://www.google.com/search?q=python+django+create+multiple+databases&rlz=1C5CHFA_enUS770US770&oq=python+django+create+multiple+databases&aqs=chrome..69i57.6344j0j7&sourceid=chrome&ie=UTF-8)? – Xcoder Nov 24 '18 at 17:27
-
Tried googling....but dint get proper answer – Gamer Nov 24 '18 at 17:32
-
Here is a [similar question](https://stackoverflow.com/questions/18547468/multiple-databases-and-multiple-models-in-django) I found. Maybe this can help a little... – Xcoder Nov 24 '18 at 17:33
-
I too saw those answers.its about switching in between dbs but they didn't say how to create 1 – Gamer Nov 24 '18 at 18:13
-
Hmm, maybe [this link](https://docs.djangoproject.com/en/2.1/topics/db/multi-db/) from the Django documentation. – Xcoder Nov 25 '18 at 00:01
-
It says ... If you attempt to access a database that you haven’t defined in your DATABASES setting, Django will raise a django.db.utils.ConnectionDoesNotExist exception – Gamer Nov 25 '18 at 11:00
1 Answers
0
Django documentation has good reference on this
https://docs.djangoproject.com/en/2.1/topics/db/multi-db/
Once you define the databases a new database other than 'default', you can use
$ ./manage.py migrate --database=new_database_name
for performing the migration or table creation

Nithin K
- 1
-
Yeah I saw those things....in my project,user wants to create a new database every time. Where in cannot cannot add those databases every time in settings... – Gamer Nov 24 '18 at 23:17