[CentralOH] Django, South, and PostgreSQL
Mark Aufdencamp
mark at aufdencamp.com
Mon Oct 14 18:54:37 CEST 2013
Thanks for the reply Brian
The SOUTH_DATABASE_ADAPTERS sets the adapter for South to utilize. I'm
not seeing tables in SQLite or Postgres. I believe that it's respected
by South because the "manage.py test" success/failure changes based on
whether the Postgres Role has createdb rights.
Does my basic South sequence look right? I can hack it back to the
default adapter if you think it looks like Im doing it right and maybe
south's getting confused.
> -------- Original Message --------
> Subject: Re: [CentralOH] Django, South, and PostgreSQL
> From: Brian Costlow <brian.costlow at gmail.com>
> Date: Mon, October 14, 2013 12:43 pm
> To: "Mailing list for Central Ohio Python User Group (COhPy)"
> <centraloh at python.org>
>
>
> Disclaimer.
>
> I've not used South on a multiple db setup, but does it honor database
> routers when doing migrations? If so, did you define one (because otherwise
> I think things happen to the 'default' db by default.)
>
> https://docs.djangoproject.com/en/dev/topics/db/multi-db/
>
> In which case your syncdb in line 4 may have built the table for that model
> in sqllite
>
>
>
> On Mon, Oct 14, 2013 at 10:48 AM, Mark Aufdencamp <mark at aufdencamp.com>wrote:
>
> > 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
> >
> >
> >
> >
> > _______________________________________________
> > CentralOH mailing list
> > CentralOH at python.org
> > https://mail.python.org/mailman/listinfo/centraloh
> ><hr>_______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> https://mail.python.org/mailman/listinfo/centraloh
More information about the CentralOH
mailing list