Search code examples
pythondjangosqliteinspectdb

Django: using more than one database with inspectdb?


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?


Solution

  • 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.