Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Django documentation" says "ensure that Django has permission to create and alter tables" so how do I do that in postgreSQL?

I'm taking EdX classes that use Ruby on Rails and python. That has given me courage to try and install and learn Django using Apach, mod_wsgi, and PostgreSQL. Following the detailed installation instructions, I first installed Apache, then mod_wsgi, and then PostgreSQL. I installed each from source and went through a little bit of tutorial with each and made sure they were properly installed. I've got a postgres user setup to run the PostgreSQL server and I was able to create a user "role" for myself as well as an admin role that my role inherits from that can create a database etc. I tried out some SQL in psql following a tutorial to make tables etc. I know how to grant privileges for a given role.

So anyway, I'm pretty close to the step where I would actually install Django from source, but I'm not sure how to follow this advice from the installation instructions:

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.

Maybe after I follow the steps to actually install Django and go through some tutorials, I'll understand exactly what needs to be setup in PostgreSQL to grant Django those permissions, but if I follow the installation instructions in order, it would seem to be saying I should setup those permissions now before installing Django. If I can get someone to tell me how to do it here before I do the install of Django, I'd appreciate it.

like image 931
Colin Keenan Avatar asked Nov 12 '12 02:11

Colin Keenan


1 Answers

In the settings.py file of a django project, there is a snippet that says something like this:

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

What this does is that it tells Django what user (postgres user in this case) and database is used in conjunction with your django project.

Normally, you will need to create this myproj_user together with the myproj_db.

When you create this user, you can choose to give it permissions like so:

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

This creates the myproj_user with superuser, createdbm createrole, login permissions allowed to the user.

And then the database like so:

CREATE DATABASE myproj_db WITH OWNER myproj_user TEMPLATE=template1 ENCODING='utf-8';

like image 73
super9 Avatar answered Nov 03 '22 01:11

super9