postgreSQL.app:创建数据库 [英] postgreSQL.app : create database
问题描述
你好我在postgreSQL中是新的,请指点一下
我有一个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:数据库testfor_psl不存在
那么如何创建数据库? ?
我使用posgreSQL.app,然后点击打开psql
有一个这样的终端:
我键入帮助
,没有任何事情发生。
请帮我谢谢
您需要在psql commad结尾放置;
正如你所看到的,在命令之后
winsome =#CREATE DATABASE testfor_psl
pre>
提示从
=#
更改为- #
。这意味着,psql仍然等待命令完成,提供;
。
此外,它更好为django项目创建数据库用户。所以这里你需要做的:
在数据库中创建用户(在psql中):
CREATE USER testfor_psl_user WITH password'pass';
创建数据库,拥有者等于该用户:
CREATE DATABASE testfor_psl ENCODING'UTF8'TEMPLATE template0 OWNER testfor_psl_user;
在django项目设置中设置凭据:
$ $ $ $ $ $ $$$$$$$$$$ :testfor_psl,
USER:testfor_psl_user,
PASSWORD:pass,
HOST:localhost,
PORT 5432,#default port
}
}
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
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:
Create user in database (in psql):
CREATE USER testfor_psl_user WITH password 'pass';
Create database with owner equals to that user:
CREATE DATABASE testfor_psl ENCODING 'UTF8' TEMPLATE template0 OWNER testfor_psl_user;
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 } }
这篇关于postgreSQL.app:创建数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!