Django database settings for production server
Asked Answered
E

1

0

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).

Encrimson answered 3/2, 2011 at 15:8 Comment(7)
You could use some #2 from net.tutsplus.com/tutorials/html-css-techniques/… because it really hard to read those settingsKnurled
1) is xyz an existing postgresql database ? 2) using a sqlite database for production environments is NOT recommended!Bildungsroman
You're using the Django 1.2+ multi-database adaptor syntax, which means you should (I think) be explicitly referring to your postgresql adaptor: "django.db.backends.postgresql_psycopg2 not just "postgresql_psycopg2". Also, do you definitely have psycopg2 installed?Ananthous
hello JackLeo, I would like to say that your reply is not concerned with this post at all.Encrimson
hello Tommaso,(1) 'xyz' is not existing database in PostGreSQL (2) I am not using SQLite for Production server. I would like to state, with Development server I am using my database which has been lay out in my filesystem(windows) say,c:\${app_name}\data.db which indeed I would like to use it Production server but when I passed the same with NAME parameter like; 'NAME': 'c:\${app_name}\data.db', it intimate me error message FATAL: database "C:/${app_name}/data.db" does not exist which is also indeed right since the particular not being existed with PostGreSGL.Encrimson
hello stevejalim, I am using Django 1.2.4; I tried your suggestion 'ENGINE': 'django.db.backends.postgresql_psycopg2' but having the same effect. Anyway, could you please explain me below aspects like; -1 How you come to know that I am using 'multi-database adaptor syntax' (even I am not being aware with it -2 What is 'single-database adaptor syntax' ? -3 And last what is 'database adaptor' ?; I tried to ggogle it but seems it very difficult to interpret since I am from Mobile domain and incidentally have to working on web applicationEncrimson
you should'nt put your name in the question :PUndeniable
M
0

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

Mashhad answered 3/2, 2011 at 18:42 Comment(3)
Hello Yuji, I am also stated the same that with PostGreSQL we have just database name like, ${database_name} ${project_name}> manage.py dbshell Giving the same error message, psql: FATAL: database "xyz" does not exist I had 2 ways to check your suggestion, 1- Either I would change database NAAE in settings.py like, 'NAME': 'postgres', //since I found it’s a default database created while PostGre installation but after that when I checked for database named 'xyz' which obviously would not be there; and later created it with command (suggested by you only) create database xyz #Plz Cont...#Encrimson
but then again it was listing there! 2- When I try with below command in order to go with dbsheell, psql.exe" -h localhost -p 5432 postgres "postgres" having the same result; database is not creating. Eventually I gone through 'pgAdmin3.exe' and created a database which would be sync later with, manage.py syncdb But look it is not serving which I would be needed. Let me explain first about the scenario. I have given a django project developed with someone else. Since, I am having just Development server database file which lay out in filesystem(windows) say, C:\${project_name}\data.db#PC#Encrimson
And would be the same corresponding file for Production server is with Developer, in his PostGre installation directory. But I didn't get that one. Now I must use C:\${project_name}\data.db But don't know how? Amit.Encrimson

© 2022 - 2024 — McMap. All rights reserved.