2014-10-02 83 views
2

你好,我在PostgreSQL新的,请指导我有点postgreSQL.app:创建数据库

我有一个Django项目

这里是settings.py:

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

我运行python manage.py syncdb

有错误:
OperationalError: FATAL: database "testfor_psl" does not exist

那么我该如何创建数据库?

我用posgreSQL.app,并单击Open psql

有这样的终端:

I型help,并没有发生。
请帮帮我。由于

enter image description here

回答

2

您需要将;放在psql commad的末尾。正如你所看到的,命令后

winsome=# CREATE DATABASE testfor_psl 

提示从=#改为-#。这意味着,psql仍然等待命令通过提供;来完成。

另外,最好为django项目创建一个数据库用户。所以,在这里你需要做什么:

  1. 创建用户数据库(在PSQL):

    CREATE USER testfor_psl_user WITH password 'pass'; 
    
  2. 创建数据库所有者等于该用户:

    CREATE DATABASE testfor_psl ENCODING 'UTF8' TEMPLATE template0 OWNER testfor_psl_user; 
    
  3. 套装django项目设置中的凭据:

    DATABASES = { 
    "default": { 
        "ENGINE": "django.db.backends.postgresql_psycopg2", 
        "NAME": "testfor_psl", 
        "USER": "testfor_psl_user", 
        "PASSWORD": "pass", 
        "HOST": "localhost", 
        "PORT": "5432", # default port 
        } 
    } 
    
+0

谢谢真的帮助!! btw是postgreSQL.app只是一个终端?我的意思是,有一个GUI我可以看到数据库? – user2492364 2014-10-02 07:54:35

+0

@ user2492364是的,psql是postgres的终端式命令接口。是的,有一个[pgadmin](http://www.pgadmin.org/),它提供了一个GUI – stalk 2014-10-02 07:57:36

0

原因help没有效果的是,你在写命令的过程中已经。 SQL命令必须以分号结尾。请注意0​​提示 - 请看它如何从=#更改为-#?这表明你正处于命令的中间。见In psql, why do some commands have no effect?

如果没有中途虽然一个命令,键入help就已经证明:

mydbname=> help 
You are using psql, the command-line interface to PostgreSQL. 
Type: \copyright for distribution terms 
     \h for help with SQL commands 
     \? for help with psql commands 
     \g or terminate with semicolon to execute query 
     \q to quit 

现在... here's the manual for the psql command

对于psql的自我使用\?的总结帮助。

有关SQL命令的列表,请使用\h

有关特定命令的帮助,请使用\h COMMAND NAME\h CREATE DATABASE以查看如何使用CREATE DATABASE命令。有关命令的更多详细信息请阅读本手册,例如the manual on CREATE DATABASE

Here's the PostgreSQL tutorial,其中涵盖了入门。

+0

比你帮忙! – user2492364 2014-10-02 08:08:02