Opened 7 years ago
Closed 7 years ago
#28499 closed Bug (fixed)
makemigrations fails on model with geometry field when the geo database is not the default one
Reported by: | Kaveh | Owned by: | nobody |
---|---|---|---|
Component: | GIS | Version: | 1.8 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Create a django app with two databases defined like this:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'whatever' ... }, 'postgres': { 'ENGINE': 'django.contrib.gis.db.backends.postgis', 'NAME': 'whatever' } }
and here is the database router:
POSTGRES_APPS = ['app1'] class PostgresRouter(object): def db_for_read(self, model, **hints): if model._meta.app_label in POSTGRES_APPS: return 'postgres' return None def db_for_write(self, model, **hints): if model._meta.app_label in POSTGRES_APPS: return 'postgres' return None def allow_relation(self, obj1, obj2, **hints): if {obj1._meta.app_label, obj2._meta.app_label}.issubset(set(POSTGRES_APPS)): return True return None def allow_migrate(self, db, app_label, model_name=None, **hints): if db == 'postgres': return app_label in POSTGRES_APPS else: return app_label not in POSTGRES_APPS
Create an app called app1
and add it to INSTALLED_APPS
:
class Shapes(models.Model): shape = models.GeometryField()
Now if you run makemigrations
, it throws the following error:
AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'
Seems like the error is because Django is using the default connection, i.e. mysql, for handling the geomtry field in app1, though this app is supposed to be part of the gis enabled database, i.e. postgres.
Change History (3)
follow-up: 2 comment:1 by , 7 years ago
comment:2 by , 7 years ago
Hi Simon, I just tried with Django 1.11 and everything works fine there. Unfortunately I'm stuck with Django 1.8.14 right now and upgrade is not an option for me.
Here's the full traceback:
Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/home/user/sandbox/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line utility.execute() File "/home/user/sandbox/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 346, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/user/sandbox/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 394, in run_from_argv self.execute(*args, **cmd_options) File "/home/user/sandbox/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 444, in execute self.check() File "/home/user/sandbox/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 482, in check include_deployment_checks=include_deployment_checks, File "/home/user/sandbox/venv/local/lib/python2.7/site-packages/django/core/checks/registry.py", line 72, in run_checks new_errors = check(app_configs=app_configs) File "/home/user/sandbox/venv/local/lib/python2.7/site-packages/django/core/checks/model_checks.py", line 28, in check_all_models errors.extend(model.check(**kwargs)) File "/home/user/sandbox/venv/local/lib/python2.7/site-packages/django/db/models/base.py", line 1205, in check errors.extend(cls._check_fields(**kwargs)) File "/home/user/sandbox/venv/local/lib/python2.7/site-packages/django/db/models/base.py", line 1282, in _check_fields errors.extend(field.check(**kwargs)) File "/home/user/sandbox/venv/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 207, in check errors.extend(self._check_backend_specific_checks(**kwargs)) File "/home/user/sandbox/venv/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 306, in _check_backend_specific_checks return connection.validation.check_field(self, **kwargs) File "/home/user/sandbox/venv/local/lib/python2.7/site-packages/django/db/backends/mysql/validation.py", line 18, in check_field field_type = field.db_type(connection) File "/home/user/sandbox/venv/local/lib/python2.7/site-packages/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'
Replying to Simon Charette:
Hello Kaveh,
Did you reproduce against 1.11 as well? Would it be possible for you to provide the full traceback of the
AttributeError
?
comment:3 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Summary: | makemigrations fails on model with geometry field when the geo database is not the defaul one → makemigrations fails on model with geometry field when the geo database is not the default one |
Per our supported versions policy, 1.8 is only receiving security and data loss fixes so we can close this. Thanks for checking.
Hello Kaveh,
Did you reproduce against 1.11 as well? Would it be possible for you to provide the full traceback of the
AttributeError
?