生产服务器的Django数据库设置 [英] Django database settings for production server

查看:136
本文介绍了生产服务器的Django数据库设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题与Django数据库配置与'postgresql_psycopg2'
如果我给任何任意名称到我的数据库,如下,

I have a problem with Django database configuration with 'postgresql_psycopg2' If I give any arbitrary name to my database like below,

    DATABASES = {
        'default': {
            'ENGINE': 'postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
            'NAME': 'xyz',                      # Or path to database file if using sqlite3.
            'USER': 'postgres',                      # Not used with sqlite3.
            'PASSWORD': '${my_password}',                  # Not used with sqlite3.
            'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
            'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
            'OPTIONS': {
                "autocommit": True,
            }
        }
    }
> 

OperationalError at /

FATAL:  database "xyz" does not exist

我冲浪很多,发现与SQLite我们必须指定绝对路径到我们的数据库相同;

I surf a lot and findout same that with SQLite we have to specify absolute path to our database; with PostGRE likewise above.

我想知道:

1)为什么我收到上述规格的错误讯息,

2)我如何使用我的数据库,我使用与开发服务器布局在文件系统(Windows)。

I would like to know:
1) Why I am getting error message with above specification and
2) How I use my database which i am using with Development server lay out in filesystem (windows).

推荐答案


我冲了很多,发现同样的
与SQLite我们必须指定
我们数据库的绝对路径;
PostGRE同上。

I surf a lot and findout same that with SQLite we have to specify absolute path to our database; with PostGRE likewise above.

为了清楚(你的措辞不是)与postgresql没有绝对路径,它只是数据库的名称。

Just to be clear (your wording isn't) with postgresql there is no absolute path, it's just the name of the database.

1:错误消息很清楚,数据库xyz不存在。

1: The error message is pretty clear, database xyz does not exist.

转到dbshel​​l( python manage.py dbshel​​l ),然后输入 \ l 。如果数据库 xyz 不在那里,输入 create database xyz ,退出postgres shell并再次尝试syncdb。

Go to the dbshell (python manage.py dbshell) and type in \l. If database xyz isn't in there, type in create database xyz, exit the postgres shell and try syncdb again.

2:对于您的开发服务器,我建议使用sqlite3以方便使用。

2: For your development server, I recommend using sqlite3 for its ease of use.

sqlite 包含在python 2.5+中,因此不需要额外的设置。只需将 ENGINE 设置为 sqlite3 ,指定要保存数据库的绝对路径, python manage.py syncdb

sqlite is included in python 2.5+, so no extra settings are required. Simply set your ENGINE to sqlite3, specify an absolute path to where you want the database saved, and python manage.py syncdb

这篇关于生产服务器的Django数据库设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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