django - "Django documentation"表示 "ensure that Django has permission to create and alter tables"那么我如何在 postgreSQL 中执行此操作?

标签 django postgresql installation

我正在学习使用 Ruby on Rails 和 python 的 EdX 类(class)。这给了我勇气尝试使用 Apach、mod_wsgi 和 PostgreSQL 安装和学习 Django。关注detailed installation instructions ,我先安装了Apache,然后是mod_wsgi,然后是PostgreSQL。我从源代码安装了每一个,并且对每一个都进行了一些教程,并确保它们已正确安装。我有一个 postgres 用户设置来运行 PostgreSQL 服务器,我能够为自己创建一个用户“角色”以及我的角色继承的管理员角色,可以创建一个数据库等。我尝试了一些 SQL psql 按照教程制作表等。我知道如何为给定角色授予权限。

所以无论如何,我已经非常接近实际从源代码安装 Django 的步骤了,但是我不确定如何遵循安装说明中的建议:

If you plan to use Django's manage.py syncdb command to automatically create database tables for your models, you'll need to ensure that Django has permission to create and alter tables in the database you're using; if you plan to manually create the tables, you can simply grant Django SELECT, INSERT, UPDATE and DELETE permissions.

也许在我按照步骤实际安装 Django 并完成一些教程之后,我会确切地理解需要在 PostgreSQL 中设置什么才能授予 Django 这些权限,但是如果我按顺序按照安装说明进行操作,看起来也就是说我应该在安装 Django 之前设置这些权限。如果我能在安装 Django 之前找人告诉我如何安装,我将不胜感激。

最佳答案

在 django 项目的 settings.py 文件中,有一个片段是这样说的:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'myproj_db',
        'USER': 'myproj_user',
        'PASSWORD': '123',
        'HOST': '',
        'PORT': '',
    },
}

它的作用是告诉 Django 什么用户(在本例中为 postgres 用户)和数据库与你的 django 项目一起使用。

通常,您需要创建此 myproj_user 以及 myproj_db

当你创建这个用户时,你可以选择像这样给它权限:

CREATE USER myproj_user WITH PASSWORD '123' SUPERUSER CREATEDB CREATEROLE LOGIN;

这将创建具有 super 用户、createdbm createrole、允许用户登录权限的 myproj_user

然后数据库像这样:

创建数据库 myproj_db WITH OWNER myproj_user TEMPLATE=t​​emplate1 ENCODING='utf-8';

关于django - "Django documentation"表示 "ensure that Django has permission to create and alter tables"那么我如何在 postgreSQL 中执行此操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13337571/

相关文章:

django - Django表单始终显示错误 “This field is required”

c - postgresql 的 Windows 安装错误。 make命令出错

python - Django编程报错1146表不存在

django - 如何检查用户是否已经在 Django 中喜欢博客文章

python - Laravel 在 django 中的 dd() 等效项

postgresql - 使用 Sequelize 在生产环境中更改模式而不丢失数据

postgresql - 是否可以将 PostGIS 用于三维空间?

macos - 如何在Mac OS X上使用MPI

php - 在 CentOS 上安装 PhalconPHP

c# - WIX:如果取消安装,请重新启动服务?