postgreSQL.app:创建数据库

编程入门 行业动态 更新时间:2024-10-25 13:18:58
本文介绍了postgreSQL.app:创建数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好我在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:创建数据库

    本文发布于:2023-10-14 12:07:44,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1491021.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:数据库   postgreSQL   app

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!