I guess you need to write a bit more:

https://docs.djangoproject.com/en/1.8/topics/db/multi-db/#allow_migrate

And sync_db is deprecated...

On 14.09.2015 13:07, Wenyao Xue wrote:
Following is my router for world app. No router for other two apps, since default database is used
Settings:
DATABASE_ROUTERS = ['world.routers.GisRouter']

router.py in world app:
class GisRouter(object):
    """
    A router to control all database operations on models in the
    auth application.
    """
    def db_for_read(self, model, **hints):
        if model._meta.app_label == 'world':
            return 'geodjango'
        return None

    def db_for_write(self, model, **hints):
        """
        Attempts to write auth models go to auth_db.
        """
        if model._meta.app_label == 'world':
            return 'geodjango'
        return None

    def allow_relation(self, obj1, obj2, **hints):
        """
        Allow relations if a model in the auth app is involved.
        """
        if obj1._meta.app_label == 'world' or \
           obj2._meta.app_label == 'world':
           return True
        return None

    def allow_syncdb(self, db, model):
        """
        Make sure the auth app only appears in the 'auth_db'
        database.
        """
        if db == 'geodjango':
            return model._meta.app_label == 'world'
        elif model._meta.app_label == 'world':
            return False
        return None

在 2015年9月14日星期一 UTC+8下午5:40:55,Jani Tiainen写道:



    On 14.09.2015 11:58, Wenyao Xue wrote:
    Hi,
    I use mysql as default database and postgres for geodjango
    related appliction.
    my settings:
    DATABASE_ROUTERS = ['world.routers.GisRouter',
    'rest_shop.routers.ShopRouter',
                        'rest_client.routers.ClientRouter']

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'fddd',
            'USER': ******,
            'PASSWORD': ******,
            'HOST': SERVER_HOST,
            'PORT': '3306',
        },
        'geodjango': {
            'ENGINE': 'django.contrib.gis.db.backends.postgis',
            'NAME': 'geo',
            'USER': *****,
            'PASSWORD': *******,
            'HOST': SERVER_HOST,
        }
    }

    during migration, error raised:

    Traceback (most recent call last):
      File "C:\Program Files (x86)\JetBrains\PyCharm
    4.5.4\helpers\pycharm\django_manage.py", line 41, in <module>
        run_module(manage_file, None, '__main__', True)
      File "C:\Python27\lib\runpy.py", line 176, in run_module
        fname, loader, pkg_name)
      File "C:\Python27\lib\runpy.py", line 82, in _run_module_code
        mod_name, mod_fname, mod_loader, pkg_name)
      File "C:\Python27\lib\runpy.py", line 72, in _run_code
        exec code in run_globals
      File "D:\src\fddd_backend\manage.py", line 10, in <module>
        execute_from_command_line(sys.argv)
      File
    
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\core\management\__init__.py",
    line 338, in execute_from_command_line
        utility.execute()
      File
    
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\core\management\__init__.py",
    line 330, in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File
    
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\core\management\base.py",
    line 393, in run_from_argv
        self.execute(*args, **cmd_options)
      File
    
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\core\management\base.py",
    line 443, in execute
        self.check()
      File
    
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\core\management\base.py",
    line 481, in check
        include_deployment_checks=include_deployment_checks,
      File
    
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\core\checks\registry.py",
    line 72, in run_checks
        new_errors = check(app_configs=app_configs)
      File
    
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\core\checks\model_checks.py",
    line 28, in check_all_models
        errors.extend(model.check(**kwargs))
      File
    
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\db\models\base.py",
    line 1205, in check
        errors.extend(cls._check_fields(**kwargs))
      File
    
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\db\models\base.py",
    line 1282, in _check_fields
        errors.extend(field.check(**kwargs))
      File
    
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\db\models\fields\__init__.py",
    line 207, in check
        errors.extend(self._check_backend_specific_checks(**kwargs))
      File
    
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\db\models\fields\__init__.py",
    line 306, in _check_backend_specific_checks
        return connection.validation.check_field(self, **kwargs)

      File
    
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\db\backends\mysql\validation.py",
    line 18, in check_field
        field_type = field.db_type(connection)
      File
    
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\contrib\gis\db\models\fields.py",
    line 247, in db_type
        return connection.ops.geo_db_type(self)
    AttributeError: 'DatabaseOperations' object has no attribute
    'geo_db_type'


    Here it looks like Django is trying to validate something
    spatially related in you MySQL db and thus creating rather
    spurious error.

    Do you have proper routing for migrations?


    Is there something wrong with my settings?
-- 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...@googlegroups.com <javascript:>.
    To post to this group, send email to django...@googlegroups.com
    <javascript:>.
    Visit this group at http://groups.google.com/group/django-users
    <http://groups.google.com/group/django-users>.
    To view this discussion on the web visit
    
https://groups.google.com/d/msgid/django-users/3fa379ce-170f-48a3-911c-c8db168c6d53%40googlegroups.com
    
<https://groups.google.com/d/msgid/django-users/3fa379ce-170f-48a3-911c-c8db168c6d53%40googlegroups.com>.
    For more options, visit https://groups.google.com/d/optout
    <https://groups.google.com/d/optout>.

--
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 <mailto:django-users+unsubscr...@googlegroups.com>. To post to this group, send email to django-users@googlegroups.com <mailto: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/267fab44-02ee-4b6a-8db0-6b668a89e721%40googlegroups.com <https://groups.google.com/d/msgid/django-users/267fab44-02ee-4b6a-8db0-6b668a89e721%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
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/55F6A358.6040302%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to