在Django中指定PostgreSQL模式 [英] Specify PostgreSQL Schema in Django

查看:274
本文介绍了在Django中指定PostgreSQL模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我喜欢通用的MVC结构以及它们的模板系统和管理界面,因此我尝试使用Django构建一些数据库前端。但是,我在使用PostgreSQL后端的某些方面遇到了麻烦。

I am trying to build some DB front-ends using Django since I like the general MVC structure as well as their template system and admin interface. However, I am having trouble with certain aspects of using a PostgreSQL back-end.

我设法弄清楚了如何使用 settings.py 文件如下:

I've managed to figure out how to specify different schemas (and databases) using the database section of the settings.py file like so:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    },
    'MPS': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'OPTIONS': {
            'options': '-c search_path=django'
        },
       'NAME': 'sandbox_manzer',
       'HOST': '192.168.2.151',
       'PORT': '5434',
       'USER': '******',
       'PASSWORD': '**********************',
    }
}

但是,当我尝试编写一些基本测试的脚本时,请详细说明此处,我遇到了问题。我的用户可以很好地创建数据库,从而构建我的test_db,但是当Django应用程序将模型构建到表中时,我收到一条错误消息,指出未指定架构 test_db。我对为test_db指定架构名称的任何帮助将不胜感激。尤其是因为我打算使用不同的架构作为逻辑分隔符为一个项目构建多个应用程序。

However, when I try and script some basic tests, as detailed here, I run into a problem. My user can create databases just fine so my test_db gets built, but when the django app goes to build the models into tables I get an error stating that No schema is specified for the test_db. Any help in how I specify schema names for the test_db would be most appreciated. Especially since I intend to build out multiple apps for a single project using different schemas as logical separators.

谢谢!

推荐答案

我想您熟悉PostgreSQL的概念方案。

I suppose you are familiar with the concept of PostgreSQL schemas.

您的应用正在数据库中寻找 django 模式(大概不存在),因为您已经明确地告诉了它。

Your app is looking for the django schema in your database (which presumably isn’t there) because you have specifically told it so.

       'options': '-c search_path=django'

为每个应用程序创建一个适当命名的架构,并在中指定它search_path

For each application, create a suitably named schema and specify it in the search_path.

这篇关于在Django中指定PostgreSQL模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆