Re: How do I manage a Non-default Django PostgreSQL database

2015-04-09 Thread Stephen M
# UPDATE

One of my issues is that my router code was based on and older version of
Django. I am not sure if this is exactly correct now but it closely 
resembles
the documentation now: 
https://docs.djangoproject.com/en/1.8/topics/db/multi-db/


class fbrPostHasteAppV0_1Router(object):
def db_for_read(self, model, **hints):
if model._meta.app_label == 'fbrPostHasteAppV0_1':
return 'fbrPostHasteDbV0_1'
return None

def db_for_write(self, model, **hints):
if model._meta.app_label == 'fbrPostHasteAppV0_1':
return 'fbrPostHasteDbV0_1'
return None

def allow_relation(self, obj1, obj2, **hints):
if obj1._meta.app_label == 'fbrPostHasteAppV0_1' or \
   obj2._meta.app_label == 'fbrPostHasteAppV0_1':
   return True
return None

def allow_migrate(self, db, app_label, model=None, **hints):
if app_label == 'fbrPostHasteAppV0_1':
return db == 'fbrPostHasteDbV0_1'
return None

The other issue is that I was not calling migrate with --database:

 python manage.py migrate --database=fbrPostHasteDb

But now I am getting another error:

django.db.utils.OperationalError: FATAL:  database "fbrPostHasteDbV0_1" 
does not exist

Continuing to figure out what else I messed up...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3890bdc8-7ff8-4426-9726-3aeb7a23651a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I manage a Non-default Django PostgreSQL database

2015-04-09 Thread Carl Meyer
On 04/09/2015 07:12 AM, Stephen M wrote:
> If Django migrations with PostgreSQL is a bit flaky (as suggested by
> S.O. comment) which backend database is reliably supported by the Django
> migrations mechanism?

The premise is false. Postgres is almost certainly the best-supported
database for Django migrations.

I'm not entirely sure what's going on in your example, but the issue is
most likely related to multiple-databases, not related to Postgres. Did
you read the documentation at
http://django.readthedocs.org/en/latest/topics/db/multi-db.html#synchronizing-your-databases
(really you should carefully read that whole page if you're using
multiple databases)? Did you use the `--database` option to the
`migrate` command?

Carl

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/55269ADD.7090608%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Re: How do I manage a Non-default Django PostgreSQL database

2015-04-09 Thread Stephen M
If Django migrations with PostgreSQL is a bit flaky (as suggested by S.O. 
comment) which backend database is reliably supported by the Django 
migrations mechanism?

On Wednesday, April 8, 2015 at 7:53:11 PM UTC-5, Stephen M wrote:
>
> Also posted to stackoverflow: How do I manage a Non-default Django 
> database 
> 
>  
>  
> [image: image] 
> 
>  
>  
>  
>  
>  
> How do I manage a Non-default Django database 
> 
> I am having trouble using my non-default database in my Django (v1.8) app. 
> When I try makemigrations and migrate the PostgreSQL database does not get 
> updated. ...
> View on stackoverflow.com 
> 
> Preview by Yahoo
>  
>
>
> I am having trouble using my non-default database in my Djaango (v1.8) 
> app. When I
> try makemigrations and migrate the PostgreSQL database does not get 
> updated.
>
> Here is my Django structure:
>
> fbrDjangoSite
> |-- db.sqlite3
> |-- manage.py
> |-- fbrDjangoSite
> |   |-- __init__.py
> |   |-- requirements.txt
> |   |-- settings.py
> |   |-- urls.py
> |   |-- wsgi.py
> |-- fbrPostHasteAppV0_1
> |   |-- __init__.py
> |   |-- admin.py
> |   |-- migrations
> |   |-- models.py
> |   |-- router.py
> |   |-- tests.py
> |   |-- urls.py
> |   |-- views.py
>
>
> # fbrPostHasteAppV0_1/admin.py
>
> from django.contrib import admin
> from fbrPostHasteAppV0_1.models import MusicianTable   # gvim 
> ../fbrPostHasteAppV0_1/models.py +/MusicianTable
> from fbrPostHasteAppV0_1.models import AlbumTable  # gvim 
> ../fbrPostHasteAppV0_1/models.py +/AlbumTable
>
> # Register your models here.
> admin.site.register(MusicianTable)
> admin.site.register(AlbumTable)
>
>
> # fbrPostHasteAppV0_1/models.py
>
> from django.db import models
>
> # Define your models/tables here.
> class MusicianTable(models.Model):
> first_name = models.CharField(max_length=50)
> last_name = models.CharField(max_length=50)
> instrument = models.CharField(max_length=100)
>
> class Meta:
> managed = True
>
> class AlbumTable(models.Model):
> artist = models.ForeignKey(MusicianTable)
> name = models.CharField(max_length=100)
> release_date = models.DateField()
> num_stars = models.IntegerField()
>
> class Meta:
> managed = True
>
> # fbrPostHasteAppV0_1/router.py
>
> class fbrPostHasteAppV0_1Router(object):
> def db_for_read(self, model, **hints):
> if model._meta.app_label == 'fbrPostHasteAppV0_1':
> return 'fbrPostHasteDbV0_1'
> return None
>
> def db_for_write(self, model, **hints):
> if model._meta.app_label == 'fbrPostHasteAppV0_1':
> return 'fbrPostHasteDbV0_1'
> return None
>
> def allow_syncdb(self, db, model):
> if db == 'fbrPostHasteDbV0_1':
> return model._meta.app_label == 'fbrPostHasteAppV0_1'
> elif model._meta.app_label == 'fbrPostHasteAppV0_1':
> return False
> return None
>
>
> # fbrDjangoSite/settings.py
>
> # ...
> INSTALLED_APPS = (
> # ...
> 'fbrPostHasteAppV0_1', # v 
> ../fbrPostHasteAppV0_1/__init__.py
> )
>
> DATABASES = {
> 'default': {
> 'ENGINE': 'django.db.backends.sqlite3',
> 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
> },
> # ...
> 'fbrPostHasteDb': {
> 'ENGINE': 'django.db.backends.postgresql_psycopg2',
> 'NAME': 'fbrPostHasteDbV0_1',
> 'USER': 'myuser',
> 'PASSWORD': '',
> 'HOST': 'myhost.us.overlord.com',
> 'PORT': '',
> },
> }
>
> DATABASE_ROUTERS = 
> ['fbrPostHasteAppV0_1.router.fbrPostHasteAppV0_1Router',]
>
>
> ...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/349558bc-eb97-4648-ab93-88f6f89bc9d0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I manage a Non-default Django PostgreSQL database

2015-04-09 Thread Stephen M
If Django migrations with PostgreSQL is a bit flaky (as suggested by S.O. 
comment) which backend database is reliably supported by the Django 
migrations mechanism?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0ed33b4d-1c7f-4ea9-9a11-74743535934b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How do I manage a Non-default Django PostgreSQL database

2015-04-08 Thread Stephen M
Also posted to stackoverflow: How do I manage a Non-default Django database 

 
 
[image: image] 

 
 
 
 
 
How do I manage a Non-default Django database 

I am having trouble using my non-default database in my Django (v1.8) app. 
When I try makemigrations and migrate the PostgreSQL database does not get 
updated. ...
View on stackoverflow.com 

Preview by Yahoo
 


I am having trouble using my non-default database in my Djaango (v1.8) app. 
When I
try makemigrations and migrate the PostgreSQL database does not get updated.

Here is my Django structure:

fbrDjangoSite
|-- db.sqlite3
|-- manage.py
|-- fbrDjangoSite
|   |-- __init__.py
|   |-- requirements.txt
|   |-- settings.py
|   |-- urls.py
|   |-- wsgi.py
|-- fbrPostHasteAppV0_1
|   |-- __init__.py
|   |-- admin.py
|   |-- migrations
|   |-- models.py
|   |-- router.py
|   |-- tests.py
|   |-- urls.py
|   |-- views.py


# fbrPostHasteAppV0_1/admin.py

from django.contrib import admin
from fbrPostHasteAppV0_1.models import MusicianTable   # gvim 
../fbrPostHasteAppV0_1/models.py +/MusicianTable
from fbrPostHasteAppV0_1.models import AlbumTable  # gvim 
../fbrPostHasteAppV0_1/models.py +/AlbumTable

# Register your models here.
admin.site.register(MusicianTable)
admin.site.register(AlbumTable)


# fbrPostHasteAppV0_1/models.py

from django.db import models

# Define your models/tables here.
class MusicianTable(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
instrument = models.CharField(max_length=100)

class Meta:
managed = True

class AlbumTable(models.Model):
artist = models.ForeignKey(MusicianTable)
name = models.CharField(max_length=100)
release_date = models.DateField()
num_stars = models.IntegerField()

class Meta:
managed = True

# fbrPostHasteAppV0_1/router.py

class fbrPostHasteAppV0_1Router(object):
def db_for_read(self, model, **hints):
if model._meta.app_label == 'fbrPostHasteAppV0_1':
return 'fbrPostHasteDbV0_1'
return None

def db_for_write(self, model, **hints):
if model._meta.app_label == 'fbrPostHasteAppV0_1':
return 'fbrPostHasteDbV0_1'
return None

def allow_syncdb(self, db, model):
if db == 'fbrPostHasteDbV0_1':
return model._meta.app_label == 'fbrPostHasteAppV0_1'
elif model._meta.app_label == 'fbrPostHasteAppV0_1':
return False
return None


# fbrDjangoSite/settings.py

# ...
INSTALLED_APPS = (
# ...
'fbrPostHasteAppV0_1', # v 
../fbrPostHasteAppV0_1/__init__.py
)

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
# ...
'fbrPostHasteDb': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'fbrPostHasteDbV0_1',
'USER': 'myuser',
'PASSWORD': '',
'HOST': 'myhost.us.overlord.com',
'PORT': '',
},
}

DATABASE_ROUTERS = 
['fbrPostHasteAppV0_1.router.fbrPostHasteAppV0_1Router',]


Here is the output when I run the migration commands:

[fbrDjangoServerV0_1.venv.py] 
/<3>django/fbrDjangoServerV0_1.venv.py/fbrDjangoSite> python manage.py 
makemigrations fbrPostHasteAppV0_1 --verbosity 3

/fobar-tools/pylibs/lib/python/Django-1.8-py2.7.egg/django/db/models/base.py:1497:
 
RemovedInDjango19Warning: Router.allow_syncdb has been deprecated and will 
stop working in Django 1.9. Rename the method to allow_migrate.
  if not router.allow_migrate(db, cls):
Did you rename the fbrPostHasteAppV0_1.Musician model to 
MusicianTable? [y/N] y
Migrations for 'fbrPostHasteAppV0_1':
  0002_auto_20150408_1653.py:
- Create model AlbumTable
- Rename model Musician to MusicianTable
- Remove field artist from album
- Delete model Album
- Add field artist to albumtable
[fbrDjangoServerV0_1.venv.py] 
/<3>django/fbrDjangoServerV0_1.venv.py/fbrDjangoSite> python manage.py 
migrate --verbosity 3 

/fobar-tools/pylibs/lib/python/Django-1.8-py2.7.egg/django/db/models/base.py:1497:
 
RemovedInDjango19Warning: Router.allow_syncdb has been deprecated and will 
stop working in Django 1.9. Rename the method