20

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?

TheEyesHaveIt
  • 980
  • 5
  • 16
  • 33

3 Answers3

35

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.

solarissmoke
  • 30,039
  • 14
  • 71
  • 73
  • When I try this I'm getting an error that `Connection 'blah' doesn't exist`. Do I need to do something prior to this? Does the directory I'm in matter? – TheEyesHaveIt Jun 02 '16 at 18:50
  • That would happen if the database file didn't exist. Check that `'C:/Users/Desktop/test2.db'` actually exists? – solarissmoke Jun 03 '16 at 02:23
11

You can specify a specific database like this:

python manage.py inspectdb --database=blah > you_app/models.py
M.Void
  • 2,764
  • 2
  • 29
  • 44
3

If you are trying @solarissmoke's answer for Django 2.*:

Don't wrap the database name with quotes, otherwise it will give you a KeyError and a ConnectionDoesnotExist error.

python manage.py inspectdb --database blah
Ritaotao
  • 31
  • 4