django - 在特定模式上运行 inspectdb

标签 django postgresql

我想使用 inspectdb以便为新引入的表构建相应的模型。但是看起来这个命令只查找 public 模式,而新表在另一个模式中。

是否可以为 inspectdb 指定模式?

最佳答案

是的,您必须通过在 settings.py 的 DATABASES 变量中添加一个选项来指定搜索路径,如下所示:

'OPTIONS': {
       'options': '-c search_path=myschema'
}

完整的 DATABASES 变量应该是:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'mydatabase',
        'USER': 'postgres',
        'PASSWORD': 'mypassword',
        'HOST': 'localhost',
        'PORT': '5432',
        'OPTIONS': {
            'options': '-c search_path=myschema'
        }
    }
}

在那之后 python manage.py inspectdb 应该可以在你的模式上工作

关于django - 在特定模式上运行 inspectdb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21986917/

相关文章:

windows - 用于将 psql 查询输出存储到变量中的批处理文件

postgresql - 为什么 pg_restore 返回 "options -d/--dbname and -f/--file cannot be used together"?

python - 如何在 Heroku 中的 Django 中安排单次事件?

python - 托管两个不同的 django 项目

javascript - Backbone.js 和 Django Rest Framework 注册和身份验证

子域的 Django 登录 cookie 在 IE8 中下划线被破坏?

postgresql - PostgreSQL 的默认连接池限制是多少?

Postgresql:如何使用 Mac OS X 查找 pg_hba.conf 文件

django - 尝试在 Docker 上使用 NGINX + Gunicorn 时,NGINX 给出 502 Bad Gateway

postgresql - Postgresql 列出具有同一行值的性别类型