Opened 8 years ago

Closed 8 years ago

#27217 closed Bug (fixed)

makemigrations crashes with "'SpatialRefSysMixin' has no attribute '_meta'" on PostGIS

Reported by: Satish V Madala Owned by: nobody
Component: GIS Version: dev
Severity: Release blocker Keywords:
Cc: Sergey Fedoseev Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Satish V Madala)

Am Using postgis as a backend and makemigrations threw back the error:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/satish/work/django/django/core/management/__init__.py", line 366, in execute_from_command_line
    utility.execute()
  File "/home/satish/work/django/django/core/management/__init__.py", line 358, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/satish/work/django/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/satish/work/django/django/core/management/base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "/home/satish/work/django/django/core/management/commands/makemigrations.py", line 173, in handle
    migration_name=self.migration_name,
  File "/home/satish/work/django/django/db/migrations/autodetector.py", line 47, in changes
    changes = self._detect_changes(convert_apps, graph)
  File "/home/satish/work/django/django/db/migrations/autodetector.py", line 198, in _detect_changes
    self._optimize_migrations()
  File "/home/satish/work/django/django/db/migrations/autodetector.py", line 362, in _optimize_migrations
    migration.operations = MigrationOptimizer().optimize(migration.operations, app_label=app_label)
  File "/home/satish/work/django/django/db/migrations/optimizer.py", line 38, in optimize
    result = self.optimize_inner(operations, app_label)
  File "/home/satish/work/django/django/db/migrations/optimizer.py", line 53, in optimize_inner
    result = operation.reduce(other, in_between, app_label)
  File "/home/satish/work/django/django/db/migrations/operations/models.py", line 213, in reduce
    return super(CreateModel, self).reduce(operation, in_between, app_label=app_label)
  File "/home/satish/work/django/django/db/migrations/operations/models.py", line 39, in reduce
    not operation.references_model(self.name, app_label)
  File "/home/satish/work/django/django/db/migrations/operations/models.py", line 119, in references_model
    model_app_label, model_name = self.model_to_key(model)
  File "/home/satish/work/django/django/db/migrations/operations/models.py", line 133, in model_to_key
    return model._meta.app_label, model._meta.object_name
AttributeError: type object 'SpatialRefSysMixin' has no attribute '_meta'

Is GeoDjango not ready for 1.11 dev version yet?

Change History (10)

comment:1 by Satish V Madala, 8 years ago

Description: modified (diff)

comment:2 by Tim Graham, 8 years ago

Summary: GeoDjango issues on Django 1.11.dev versionmakemigrations crashes with "'SpatialRefSysMixin' has no attribute '_meta'" on PostGIS
Triage Stage: UnreviewedAccepted

Bisected the regression to 7fc4c1db627807874966e4f96b34cff7c9af886f. Steps to reproduce and a sample project are on django-users.

comment:3 by Melvyn Sopacua, 8 years ago

Reproduction steps posted on mailing list:

  1. Create a python3 virtualenv and activate it
  2. pip install git+https://github.com/django/django.git
  3. pip install psycopg2
  4. django-admin startproject projectname
  5. Change the db backend to postgis in settings file
  6. python manage.py makemigrations
Version 0, edited 8 years ago by Melvyn Sopacua (next)

comment:4 by Melvyn Sopacua, 8 years ago

If above steps are accurate, then please verify if adding 'django.contrib.gis' to INSTALLED_APPS (which you haven't done in above steps) resolves the issue. The documentation on this is ambiguous. It suggests one can start the dev server without this step (and probably can), but the GeoDjango framework is improperly configured at that time.

in reply to:  4 comment:5 by Satish V Madala, 8 years ago

I've missed documenting the step, I've added 'django.contrib.gis' to INSTALLED_APPS. Issue is same.

Replying to melvyn-sopacua:

If above steps are accurate, then please verify if adding 'django.contrib.gis' to INSTALLED_APPS (which you haven't done in above steps) resolves the issue. The documentation on this is ambiguous. It suggests one can start the dev server without this step (and probably can), but the GeoDjango framework is improperly configured at that time.

comment:6 by Claude Paroz, 8 years ago

Cc: Sergey Fedoseev added

comment:7 by Satish V Madala, 8 years ago

Hi,

Is there a patch for this bug?

Thanks.

comment:8 by Simon Charette, 8 years ago

Not so far but it should be only a matter of adjusting this line to also check for isinstance(base, models.base.ModelBase).

comment:9 by Tim Graham, 8 years ago

Has patch: set

comment:10 by GitHub <noreply@…>, 8 years ago

Resolution: fixed
Status: newclosed

In a44fc00:

Fixed #27217 -- Fixed crash in CreateModel optimization with models that use mixins.

Thanks Simon Charette for review.

Note: See TracTickets for help on using tickets.
Back to Top