Hi django devs,

I have two models and need to store to different dbs.I want this field
to be a
foreign key from Test2, stored on the "test2" database, to the Test1
model stored on the "default" database.The codes are:

# model in app test1,store to default
class Test1(models.Model):
    name = models.CharField(max_length=30,verbose_name="name")
    class Meta:
        verbose_name = "test1"
        verbose_name_plural = "test1"
    def __unicode__(self):
        return self.name
# model in app test2,store to test2
class Test2(models.Model):
    name = models.CharField(max_length=30,verbose_name="test2")
    test1 =
models.ForeignKey('test1.Test1',verbose_name="FK_test1",blank=True,null=Tru
e)
    class Meta:
        verbose_name = "test2"
        verbose_name_plural = "test2"
    def __unicode__(self):
        return self.name

# my dbrouter
#The code is written in the root directory of the __init__.py file
class MyDBRouter(object):
    def db_for_read(self, model, **hints):
        return self.__app_router(model)
    def db_for_write(self, model, **hints):
        return self.__app_router(model)
    def allow_relation(self, obj1, obj2, **hints):
        #return obj1._meta.app_label == obj2._meta.app_label
        return True
    def allow_syncdb(self, db, model):
        return self.__app_router(model) == db
    def __app_router(self, model):
        # Can also be written like this,it also works well
        # if model.__name__ == 'Test2':
        if model._meta.app_label == 'test2':
            return 'test2'
        else:
            return 'default'

# at last,my settings
DATABASES = {
    'default': {
        'ENGINE': 'mysql',
        'NAME': 'test1',
        'USER': 'root',
        'PASSWORD': 'root',
        'HOST': '',
        'PORT': '3306',
    },
    'test2': {
        'ENGINE': 'mysql',
        'NAME': 'test2',
        'USER': 'root',
        'PASSWORD': 'root',
        'HOST': '',
        'PORT': '3306',
    }
}
DATABASE_ROUTERS = ['my_project_name.MyDBRouter',]

Questions:
    All of these code work well on django 1.2.3,but once I use django
1.2.5 or 1.3 rc1,It does not work and have same exception.The
exception information is:
DatabaseError at /admin/test2/test2/add/
(1146, "Table 'test1.test2_test2' doesn't exist")
Request Method:         POST
Request URL:    http://192.168.1.111/admin/test2/test2/add/
Django Version:         1.3 rc 1
Exception Type:         DatabaseError
Exception Value:
(1146, "Table 'test1.test2_test2' doesn't exist")
Exception Location:     build/bdist.linux-i686/egg/MySQLdb/
connections.py
in defaulterrorhandler, line 36
Python Executable:      /usr/local/bin/python
Python Version:         2.6.5
Python Path:
['/root/testadmin',
 '/usr/local/lib/python2.6/site-packages/setuptools-0.6c11-
py2.6.egg',
 '/usr/local/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-
linux-i686.egg',
 '/usr/local/lib/python26.zip',
 '/usr/local/lib/python2.6',
 '/usr/local/lib/python2.6/plat-linux2',
 '/usr/local/lib/python2.6/lib-tk',
 '/usr/local/lib/python2.6/lib-old',
 '/usr/local/lib/python2.6/lib-dynload',
 '/usr/local/lib/python2.6/site-packages']
But the most strange thing is that:use the following command:
python manage.py syncdb
python manage.py syncdb --database='test2'
I can create table correctly in different database,also on django
1.2.5 or 1.3 rc1,I do not know whether other people come across this
problem.I also compared the differences between the different
versions
of the django source codes about this feature,but did not find
problems.

I wonder to know is this a bug of django1.2.3?Or this feature can be
used
in django-1.2.3, but why i can't use it at a higher version.

I use the test environment is:centos5.X+python2.6+mysql

any suggestions?
thx for your time,

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

Reply via email to