[CentralOH] Django, South, and PostgreSQL

Mark Aufdencamp mark at aufdencamp.com
Mon Oct 14 16:48:31 CEST 2013


Hi All,

I'm hoping for a little help in getting my Django tables created in
Postgres with South.   I've outlined my steps below.

Any ideas on why my table isn't being created?

Postgres use access rights?

A problem with South and Django's multiple database adapters?

Missing something?

TIA 
Mark Aufdencamp


Steps for implementation:

1. I've created a database and role in Postgres.

createuser -U postgres cloudonyms -P
createdb -U postgres -E utf8 -O cloudonyms cloudonyms -T postgistemplate
psql -U postgres cloudonyms -c "GRANT ALL ON ALL TABLES IN SCHEMA public
TO cloudonyms;"
psql -U postgres cloudonyms -c "GRANT ALL ON ALL SEQUENCES IN SCHEMA
public TO cloudonyms;"
psql -U postgres cloudonyms -c "GRANT ALL ON ALL FUNCTIONS IN SCHEMA
public TO cloudonyms;"


2. I've configured my setting.py in Django with the database connection
info.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', # Add
'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        #'NAME':
'/Users/maaufden/Documents/Aptana-RadRails-Workspace/cloudonyms/sqlite.db',
                     # Or path to database file if using sqlite3.
         'NAME': os.path.join( PROJECT_DIR, 'sqlite.db'),               
      # Or path to database file if using sqlite3.
       # The following settings are not used with sqlite3:
        'USER': '',
        'PASSWORD': '',
        'HOST': '',                      # Empty for localhost through
domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '',                      # Set to empty string for
default.
    },
    'cloudonyms': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'cloudonyms',
        'USER': 'cloudonyms',
        'PASSWORD': 'network-man',
        'HOST': '',                      # Empty for localhost through
domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '',                      # Set to empty string for
default.
    },
}
SOUTH_DATABASE_ADAPTERS = {'cloudonyms':'south.db.postgresql_psycopg2'}


3. I've created an app and model in Django.

python manage.py startapp networks

networks/models.py
from django.db import models

# Create your models here.
class Networks(models.Model):
    title = models.CharField(max_length=100)
    state = models.CharField(max_length=100)
    icon = models.CharField(max_length=255)
    disconnectedIconClass = models.CharField(max_length=40)
    connectedIconClass = models.CharField(max_length=40)


4. I've run manage.py dbsync

python manage.py syncdb


5. I've created an initial south migration and have a db.create_table in
the forward function.

python manage.py schemamigration networks --initial


6. When I try to migrate, the table doesn't get created in Postgres

python manage.py migrate networks

Running migrations for networks:
- Nothing to migrate.
 - Loading initial data for networks.
Installed 0 object(s) from 0 fixture(s)


7. If I give the Postgres Role createdb permissions, manage.py test will
run.

psql -U postgres -d cloudonyms
ALTER ROLE cloudonyms WITH CREATEDB;
python manage.py test






More information about the CentralOH mailing list