Auth app in separate database

558 views
Skip to first unread message

Chris

unread,
Mar 28, 2012, 7:08:47 PM3/28/12
to Django users
Has anyone been successful in putting the auth application in a
separate database so that users can be shared with different django
projects?

When I try to put the auth application in a different database I get
an error with syncdb:

django.db.utils.DatabaseError: relation "auth_permission" does not
exist
LINE 1: ...ntent_type_id", "auth_permission"."codename" FROM
"auth_perm...

Amit

unread,
Mar 29, 2012, 12:00:08 AM3/29/12
to Django users
While running syncdb command django uses default database to create
tables.
You can do one thing, first create default database using syncdb then
copy auth related tables to another database.
Then define router for auth. You can get more ref form django
documentatiion.

Regards,
Amit

Josh Cartmell

unread,
Mar 29, 2012, 12:15:49 PM3/29/12
to Django users
Couldn't he also just add the router before syncdb and then they would
be created in the correct database?

Chris take a look at this documentation if you haven't already, it
explains routers which tell Django which database to use for a
particular query:
https://docs.djangoproject.com/en/dev/topics/db/multi-db/#using-routers

Chris

unread,
Mar 29, 2012, 1:37:02 PM3/29/12
to django...@googlegroups.com
I setup my router following the docs.

Here's what my router.py looks like:

AUTH_APPS = ('auth',)

class MyRouter(object):
    def db_for_read(self, model, **hints):
        if model._meta.app_label in AUTH_APPS:
            return 'auth'
        return None

    def db_for_read(self, model, **hints):
        if model._meta.app_label in AUTH_APPS:
            return 'auth'
        return None
   
    def allow_syncdb(self, db, model):
        "Make sure the Auth apps only appears on the 'auth' db"
        if db == 'auth':
            return model._meta.app_label in AUTH_APPS
        elif model._meta.app_label in AUTH_APPS:
            return False
        return None

Removing auth from the default database seems to cause issues with contenttypes and create errors on syncdb. auth and contenttypes seem to be dependent on each other.
Reply all
Reply to author
Forward
0 new messages