2014-10-02 48 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