[CentralOH] Django, South, and PostgreSQL

Brandon Lorenz blorenz at gmail.com
Thu Oct 17 15:27:31 CEST 2013


Mark,

Your database backend engine is incorrect for PostGIS. It should
be 'ENGINE': 'django.contrib.gis.db.backends.postgis' or it won't be able
to do spatial stuff.

  Brandon


On Mon, Oct 14, 2013 at 2:01 PM, Mark Aufdencamp <mark at aufdencamp.com>wrote:

> Thanks Brian!
>
> Sounds like I have half of what I need in place for the multiple
> adapters.  I looked at the routing configs, but it wasn't obvious I'd
> need both telling South which database and which tables.
>
> I'm going to back down to one db and try it with both to make sure I can
> touch each one with South, then I'll play with the routing.
>
> I'll need two databases with the project I'm working on.  In production
> it will be an existing MySQL db and a Postgres db for GIS stuff.  I also
> have a Java Tomcat Server (GeoServer) for my base maps and ActiveMQ for
> WebSockets in the mix .  Web front end will utilize Backbone, Stomp, and
> OpenLayers.  There will be a mobile PhoneGap client for metadata with
> location info.  Should be interesting when I get it working.
>
>
> > -------- Original Message --------
> > Subject: Re: [CentralOH] Django, South, and PostgreSQL
> > From: Brian Costlow <brian.costlow at gmail.com>
> > Date: Mon, October 14, 2013 1:43 pm
> > To: "Mailing list for Central Ohio Python User Group (COhPy)"
> > <centraloh at python.org>
> >
> >
> > Mark
> >
> > SOUTH_DATABASE_ADAPTERS = {'cloudonyms':'south.db.postgresql_psycopg2'}
> >
> > basically tells South that when it sees the django db alias 'cloudonyms'
> it
> > should use the postgresql database adapter. But it doesn't map your db
> > models themselves to the cloudonyms alias.
> >
> > You have two databases defined in your settings, and I don't see anything
> > to tell django "when the model is Networks use cloudonyms and not
> default".
> > Which usually means Django will use default. Which South should try to
> > honor.
> >
> > So I'm surprised you're not seeing anything in either db. From what I can
> > see I would expect it to be in sqlite.
> >
> > Is your app app defined in the settings file? Maybe Django is not picking
> > it up at all. It needs an entry in Installed_Apps to be recognized.
> >
> > Unless you really need two db backends, it will always make your life
> > easier in Django to use 'default' as the db alias.
> >
> >
> >
> >
> >
> >
> >
> >
> > On Mon, Oct 14, 2013 at 12:54 PM, Mark Aufdencamp <mark at aufdencamp.com
> >wrote:
> >
> > > 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
> > > _______________________________________________
> > > 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
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> https://mail.python.org/mailman/listinfo/centraloh
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20131017/b9beccb4/attachment.html>


More information about the CentralOH mailing list