Thursday, March 29, 2012

Re: Auth app in separate database

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.

On Thursday, 29 March 2012 12:15:49 UTC-4, Josh Cartmell wrote:
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

On Mar 28, 9:00 pm, Amit <pathakami...@gmail.com> wrote:
> 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
>
> On Mar 29, 4:08 am, Chris <crflei...@gmail.com> wrote:
>
>
>
>
>
>
>
> > 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...

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/ZaoLWNLzD3sJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment