migration error "geo_db_type" when using postgres as second database for geodjango

245 views
Skip to first unread message

Wenyao Xue

unread,
Sep 14, 2015, 5:12:25 AM9/14/15
to Django users
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'


Is there something wrong with my settings?

Jani Tiainen

unread,
Sep 14, 2015, 5:40:55 AM9/14/15
to django...@googlegroups.com
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.
To post to this group, send email to django...@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/3fa379ce-170f-48a3-911c-c8db168c6d53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Wenyao Xue

unread,
Sep 14, 2015, 6:07:45 AM9/14/15
to Django users
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写道:

Jani Tiainen

unread,
Sep 14, 2015, 6:37:56 AM9/14/15
to django...@googlegroups.com
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...

Wenyao Xue

unread,
Sep 14, 2015, 7:35:15 AM9/14/15
to Django users
I upgraded my router using allow_migrate, but it didn't solve my problem

在 2015年9月14日星期一 UTC+8下午6:37:56,Jani Tiainen写道:

Tim Graham

unread,
Sep 14, 2015, 12:21:58 PM9/14/15
to Django users

Wenyao Xue

unread,
Sep 14, 2015, 10:10:09 PM9/14/15
to Django users
Thanks, I guess I have to wait for 1.9 to release then

在 2015年9月15日星期二 UTC+8上午12:21:58,Tim Graham写道:

Thomas Lockhart

unread,
Sep 14, 2015, 10:58:02 PM9/14/15
to django...@googlegroups.com
On 9/14/15 7:10 PM, Wenyao Xue wrote:
Thanks, I guess I have to wait for 1.9 to release then

在 2015年9月15日星期二 UTC+8上午12:21:58,Tim Graham写道:
The fix seems to be fairly compact. Any chance of getting it into the 1.8.x LTS branch?

- Tom

Tim Graham

unread,
Sep 15, 2015, 10:07:30 AM9/15/15
to Django users
The backport isn't trivial because of this removal that happened on 1.9 which would need to be accounted for on 1.8: https://github.com/django/django/commit/3b570dbcdb605cc6ee7e8796e1533fdd40c92362

If someone wants to do that work, we could probably accept a patch for 1.8.
Reply all
Reply to author
Forward
0 new messages