My settings file's database section looks like this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'C:/Users/Desktop/test.db'
},
'blah':{
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'C:/Users/Desktop/test2.db'
}
}
When I run the command python manage.py inspectdb > models.py
, I only get the model generated for the default database, but not the second one. How could I get both models generated?
Django's admin doesn't have any explicit support for multiple databases. If you want to provide an admin interface for a model on a database other than that specified by your router chain, you'll need to write custom ModelAdmin classes that will direct the admin to use a specific database for content.
Django Inspectdb Refactor will automatically create the required folders and create separate python files for each model. You can install it via pip or to get the latest version clone this repo. Add ``inspectdb_refactor`` to your ``INSTALLED_APPS`` inside settings.py of your project. make models in that particular app.
From the documentation:
--database DATABASE
Specifies the database to introspect. Defaults to
default
.
So you can inspect your second database with:
python manage.py inspectdb --database blah
You cannot inspect both at the same time.
You can specify a specific database like this:
python manage.py inspectdb --database=blah > you_app/models.py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With