Thank you, Reinout.

I changed the definition of 'allow_syncdb' to the following:
<code>
    def allow_syncdb(self, db, model):
        # db is a string of database name.
        label = model._meta.app_label
        if label == 'books':
            dbName = 'test'
        else:
            dbName = None
        if dbName == db:
            return True
        else:
            return None
</code>
Now './manage.py syncdb' can run through with no problems. However, it
doesn't create the database 'test.sqlite', which means the models in the
app, books, are still installed in the default database.

Also, I am using django v1.3.

In addition, about the *two* things you mentioned, how can I test for that?
It seems all the functions defined in the class DBRouter are called
internally by django. I don't know how to make django print something so
that I know what's going on when django calls those function.

Again, thank you very much.


On Wed, Aug 24, 2011 at 2:15 AM, Reinout van Rees <rein...@vanrees.org>wrote:

> On 23-08-11 01:31, Jim wrote:
>
>>     def allow_syncdb(self, db, model):
>>         # db is a string of database name.
>>         label = model._meta.app_label
>>         if label == 'books':
>>             dbName = 'test'
>>         else:
>>             dbName = None
>>         return dbName == db
>>
>
> I'd do the "if" part as follows:
>
>        if label == 'books':
>            if db == 'test':
>                return True
>            return False
>        if db == 'test':
>            return False
>        return None  # None means 'no opinion'.
>
> iirc allow_syncdb() ought to return True/False to indicate whether a
> certain model should be synced to a certain database. So you need to make
> sure *two* things:
>
> - Your special models only end up in your special database and not in
> another.
>
> - Other models (like the django_content_type table that gives you
> problems!) should not end up in your special deatabase.
>
>
>
> Reinout
>
> --
> Reinout van Rees                    http://reinout.vanrees.org/
> rein...@vanrees.org             
> http://www.nelen-schuurmans.**nl/<http://www.nelen-schuurmans.nl/>
> "If you're not sure what to do, make something. -- Paul Graham"
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> 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 <django-users%2bunsubscr...@googlegroups.com>.
> For more options, visit this group at http://groups.google.com/**
> group/django-users?hl=en<http://groups.google.com/group/django-users?hl=en>
> .
>
>

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

Reply via email to