问题
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
I surf a lot and findout same that with SQLite we have to specify absolute path to our database; with PostGRE likewise above.
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).
回答1:
I surf a lot and findout same that with SQLite we have to specify absolute path to our database; with PostGRE likewise above.
Just to be clear (your wording isn't) with postgresql there is no absolute path, it's just the name of the database.
1: The error message is pretty clear, database xyz does not exist.
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: For your development server, I recommend using sqlite3 for its ease of use.
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
来源:https://stackoverflow.com/questions/4887851/django-database-settings-for-production-server