﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
23041	Double proxy models break migrations	Maik Hoepfel	Andrew Godwin	"I'm working on adding Django 1.7 support to django-oscar. We have [https://github.com/tangentlabs/django-oscar/blob/master/oscar/apps/offer/models.py#L1529 two layers of proxy models] on top of a Benefit model. That is unorthodox and maybe not the best design decision, but worked in Django before 1.7. It breaks when trying to apply new-style migrations.

This happens both with the release candidate and a checkout from stable/1.7.x.

As a minimal test case, I created a new Django project and app, and have the following models:


{{{
from django.db import models

class Benefit(models.Model):

    # not needed, just showing that the model isn't empty
    type = models.CharField(""Type"", max_length=128, blank=True)


class ShippingBenefit(Benefit):

    class Meta:
        proxy = True


class ShippingAbsoluteDiscountBenefit(ShippingBenefit):


    class Meta:
        proxy = True
}}}

I then run {{{ rm -r testapp/migrations/ db.sqlite3 && ./manage.py makemigrations testapp && ./manage.py migrate }}} to reproduce:

{{{
Migrations for 'testapp':
  0001_initial.py:
    - Create model Benefit
    - Create proxy model ShippingAbsoluteDiscountBenefit
    - Create proxy model ShippingBenefit
Operations to perform:
  Apply all migrations: admin, contenttypes, testapp, auth, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying sessions.0001_initial... OK
  Applying testapp.0001_initial...Traceback (most recent call last):
  File ""./manage.py"", line 10, in <module>
    execute_from_command_line(sys.argv)
  File ""/home/m/.virtualenvs/proxyfun/local/lib/python2.7/site-packages/django/core/management/__init__.py"", line 385, in execute_from_command_line
    utility.execute()
  File ""/home/m/.virtualenvs/proxyfun/local/lib/python2.7/site-packages/django/core/management/__init__.py"", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File ""/home/m/.virtualenvs/proxyfun/local/lib/python2.7/site-packages/django/core/management/base.py"", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File ""/home/m/.virtualenvs/proxyfun/local/lib/python2.7/site-packages/django/core/management/base.py"", line 337, in execute
    output = self.handle(*args, **options)
  File ""/home/m/.virtualenvs/proxyfun/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py"", line 160, in handle
    executor.migrate(targets, plan, fake=options.get(""fake"", False))
  File ""/home/m/.virtualenvs/proxyfun/local/lib/python2.7/site-packages/django/db/migrations/executor.py"", line 62, in migrate
    self.apply_migration(migration, fake=fake)
  File ""/home/m/.virtualenvs/proxyfun/local/lib/python2.7/site-packages/django/db/migrations/executor.py"", line 96, in apply_migration
    migration.apply(project_state, schema_editor)
  File ""/home/m/.virtualenvs/proxyfun/local/lib/python2.7/site-packages/django/db/migrations/migration.py"", line 107, in apply
    operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
  File ""/home/m/.virtualenvs/proxyfun/local/lib/python2.7/site-packages/django/db/migrations/operations/models.py"", line 33, in database_forwards
    apps = to_state.render()
  File ""/home/m/.virtualenvs/proxyfun/local/lib/python2.7/site-packages/django/db/migrations/state.py"", line 71, in render
    raise InvalidBasesError(""Cannot resolve bases for %r\nThis can happen if you are inheriting models from an app with migrations (e.g. contrib.auth)\n in an app with no migrations; see https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies for more"" % new_unrendered_models)
django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [<ModelState: 'testapp.ShippingAbsoluteDiscountBenefit'>]
This can happen if you are inheriting models from an app with migrations (e.g. contrib.auth)
 in an app with no migrations; see https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies for more
}}}

"	Bug	closed	Migrations	1.7-rc-1	Release blocker	fixed			Unreviewed	0	0	0	0	0	0
