Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgreSQL.app : create database

Hello I'm new in postgreSQL,Please guide me a bit

I have a django project

here is settings.py :

DATABASES = {
"default": {
    "ENGINE": "django.db.backends.postgresql_psycopg2",
    "NAME": "testfor_psl",
    "USER": "",
    "PASSWORD": "",
    "HOST": "localhost",
    "PORT": "",
    }
}

And I run python manage.py syncdb

There is error:
OperationalError: FATAL: database "testfor_psl" does not exist

So how can I create db??

I use posgreSQL.app, and click the Open psql

There is a terminal like this :

I type help,and nothing happen.
Please help me. Thanks

enter image description here

like image 287
user2492364 Avatar asked Feb 11 '23 21:02

user2492364


1 Answers

You need to put ; at the end of psql commad. As you can see, after command

winsome=# CREATE DATABASE testfor_psl

the prompt is changed from =# to -#. It means, that psql still wait for the command to be completed by providing ;.

Also, it is better to create a database user for django project. So here what you need to do:

  1. Create user in database (in psql):

    CREATE USER testfor_psl_user WITH password 'pass';
    
  2. Create database with owner equals to that user:

    CREATE DATABASE testfor_psl ENCODING 'UTF8' TEMPLATE template0 OWNER testfor_psl_user;
    
  3. Set credentials in django project settings:

    DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql_psycopg2",
        "NAME": "testfor_psl",
        "USER": "testfor_psl_user",
        "PASSWORD": "pass",
        "HOST": "localhost",
        "PORT": "5432",  # default port
        }
    }
    
like image 151
stalk Avatar answered Feb 18 '23 20:02

stalk