Django: using more than one database with inspectdb?

房东的猫 提交于 2020-01-01 09:03:12

问题


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?


回答1:


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.




回答2:


You can specify a specific database like this:

python manage.py inspectdb --database=blah > you_app/models.py



回答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


来源:https://stackoverflow.com/questions/37581885/django-using-more-than-one-database-with-inspectdb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!