Opened 10 years ago

Closed 10 years ago

#22708 closed Bug (fixed)

InvalidBasesError when running manage.py migrate

Reported by: strelnikovdmitrij Owned by: nobody
Component: Migrations Version: 1.7-beta-2
Severity: Release blocker Keywords:
Cc: cmawebsite@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

what does it exactly means and how to handle it?
all the time after adding new model this raise error
if not raising, (on very basic models add) and new model should be created - its actually don't create any

Django version 1.7b4
Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin

Migrations for 'account':
  0004_auto_20140527_1518.py:
    - Create model LoginFailed
    - Alter field ip on loginactivity
dmitrij$ python manage.py migrate
Operations to perform:
  Synchronize unmigrated apps: ***
  Apply all migrations: account, ***
Synchronizing apps without migrations:
  Creating tables...
  Installing custom SQL...
  Installing indexes...
Running migrations:
  Applying account.0004_auto_20140527_1518...Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/dmitrij/dev/django/django/core/management/__init__.py", line 427, in execute_from_command_line
    utility.execute()
  File "/Users/dmitrij/dev/django/django/core/management/__init__.py", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/dmitrij/dev/django/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/dmitrij/dev/django/django/core/management/base.py", line 337, in execute
    output = self.handle(*args, **options)
  File "/Users/dmitrij/dev/django/django/core/management/commands/migrate.py", line 146, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/Users/dmitrij/dev/django/django/db/migrations/executor.py", line 62, in migrate
    self.apply_migration(migration, fake=fake)
  File "/Users/dmitrij/dev/django/django/db/migrations/executor.py", line 90, in apply_migration
    if self.detect_soft_applied(migration):
  File "/Users/dmitrij/dev/django/django/db/migrations/executor.py", line 134, in detect_soft_applied
    apps = project_state.render()
  File "/Users/dmitrij/dev/django/django/db/migrations/state.py", line 68, in render
    raise InvalidBasesError("Cannot resolve bases for %r" % new_unrendered_models)
django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [<django.db.migrations.state.ModelState object at 0x102f19ad0>, <django.db.migrations.state.ModelState object at 0x102f19b90>, <django.db.migrations.state.ModelState object at 0x102f19c50>]

---0004_auto_20140527_1518.py---

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import django.utils.timezone
from django.conf import settings


class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('account', '0003_loginactivity'),
    ]

    operations = [
        migrations.CreateModel(
            name='LoginFailed',
            fields=[
                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                ('user', models.ForeignKey(to_field='id', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
                ('username', models.CharField(max_length=120)),
                ('password', models.CharField(max_length=120, null=True, blank=True)),
                ('created', models.DateField(default=django.utils.timezone.now)),
                ('ip', models.GenericIPAddressField(null=True, blank=True)),
            ],
            options={
            },
            bases=(models.Model,),
        ),
        migrations.AlterField(
            model_name='loginactivity',
            name='ip',
            field=models.GenericIPAddressField(),
        ),
    ]

Attachments (1)

testproject.tar.gz (2.1 KB ) - added by Ben Davis 10 years ago.
Example project to reproduce InvalidBaseError

Download all attachments as: .zip

Change History (18)

comment:1 by Tim Graham, 10 years ago

Description: modified (diff)

Could you include the models as well? Particularly, if there are any that do more than just inherit from models.Model. I suspect the problem lies somewhere in there.

comment:2 by Tim Graham, 10 years ago

Summary: migrations doesn't migrateInvalidBasesError when running manage.py migrate

comment:3 by strelnikovdmitrij, 10 years ago

hi Timo,
all my models are inherit from models.Model or AbstractBase for User custom model
if you still want to provide them - which one do you need?

regards,
Dmitrij

comment:4 by Tim Graham, 10 years ago

We need a minimal set of models to reproduce the issue. #22743 seems to be a duplicate and the models provided there may be enough.

comment:5 by Tim Graham, 10 years ago

I couldn't reproduce this with the models in #22743. I wonder if it might be more than just the models themselves. For example, #22660 reports this error when there are dependencies between migrate and unmigrated apps. Could this be the same issue?

comment:6 by Tim Graham, 10 years ago

Resolution: needsinfo
Status: newclosed

Please retest with the latest master or stable/1.7.x and reopen with details if this is still an issue.

comment:7 by anonymous, 10 years ago

Resolution: needsinfo
Status: closednew

This seems to have regressed. I can reproduce the error with these models on today's stable/1.7.x

from django.contrib.contenttypes.models import ContentType
from django.db import models


class PageElement(models.Model):
    content_type = models.ForeignKey(ContentType)


class Link(PageElement):
    href = models.CharField(max_length=255)

comment:8 by Ben Davis, 10 years ago

Severity: NormalRelease blocker

Sorry, posted that last comment anonymously (and before finishing). I've attached an example project to reproduce the exception. This example is fairly basic and doesn't use swappable models. Just basic model inheritance. The starnge thing is, if you rename "PageEleemnt" to "BaseElement", the migration works. This leads me to believe theirs a dict or set is being used somewhere where order is important.

by Ben Davis, 10 years ago

Attachment: testproject.tar.gz added

Example project to reproduce InvalidBaseError

comment:9 by Collin Anderson, 10 years ago

I can confirm that the simple testproject does not work either on the latest 1.7.x or on master, and that it works fine if the model is named BaseElement.

Version 0, edited 10 years ago by Collin Anderson (next)

comment:10 by Collin Anderson, 10 years ago

I believe the issue is that the auto-generated migration creates Link first (with base PageElement), then creates PageElement second:

    operations = [
        migrations.CreateModel(
            name='Link',
            fields=[
                ('href', models.CharField(max_length=255)),
            ],
            options={
            },
            bases=('testapp.pageelement',),
        ),
        migrations.CreateModel(
            name='PageElement',
            fields=[
                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                ('content_type', models.ForeignKey(to='contenttypes.ContentType', to_field='id')),
            ],
            options={
            },
            bases=(models.Model,),
        ),
        migrations.AddField(
            model_name='link',
            name='pageelement_ptr',
            field=models.OneToOneField(auto_created=True, primary_key=True, to_field='id', serialize=False, to='testapp.PageElement'),
            preserve_default=True,
        ),
    ]

comment:11 by Collin Anderson, 10 years ago

Cc: cmawebsite@… added

comment:12 by Tim Graham, 10 years ago

Triage Stage: UnreviewedAccepted

comment:13 by Andrew Godwin <andrew@…>, 10 years ago

Resolution: fixed
Status: newclosed

In fe262c0b848c96ef624680d43dc78eae55157967:

Fixed #22708: Typo in autodetector base dependency gen

comment:14 by Andrew Godwin <andrew@…>, 10 years ago

In 48a2e027bf5eeca75b7694ea0b3c271dc46ae094:

[1.7.x] Fixed #22708: Typo in autodetector base dependency gen

comment:15 by Piotr Maliński, 10 years ago

I've made a stabke.1.7.x checkout now with that commit and still contenttypes doesn't want to migrate.

comment:16 by stanislas.guerra@…, 10 years ago

Resolution: fixed
Status: closednew

Hi there,

Same problem here with a fresh checkout of stable/1.7.x when running my tests (which used to works a few weeks ago):

Creating test database for alias 'default'...
Traceback (most recent call last):
  File "manage.py", line 9, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/stan/src/venv_dj_1_7/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/Users/stan/src/venv_dj_1_7/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/stan/src/venv_dj_1_7/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/commands/test.py", line 50, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "/Users/stan/src/venv_dj_1_7/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/stan/src/venv_dj_1_7/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/commands/test.py", line 71, in execute
    super(Command, self).execute(*args, **options)
  File "/Users/stan/src/venv_dj_1_7/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/base.py", line 337, in execute
    output = self.handle(*args, **options)
  File "/Users/stan/src/venv_dj_1_7/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/commands/test.py", line 88, in handle
    failures = test_runner.run_tests(test_labels)
  File "/Users/stan/src/venv_dj_1_7/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/test/runner.py", line 147, in run_tests
    old_config = self.setup_databases()
  File "/Users/stan/src/venv_dj_1_7/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/test/runner.py", line 109, in setup_databases
    return setup_databases(self.verbosity, self.interactive, **kwargs)
  File "/Users/stan/src/venv_dj_1_7/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/test/runner.py", line 299, in setup_databases
    serialize=connection.settings_dict.get("TEST_SERIALIZE", True),
  File "/Users/stan/src/venv_dj_1_7/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/db/backends/creation.py", line 374, in create_test_db
    test_flush=True,
  File "/Users/stan/src/venv_dj_1_7/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/__init__.py", line 115, in call_command
    return klass.execute(*args, **defaults)
  File "/Users/stan/src/venv_dj_1_7/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/base.py", line 337, in execute
    output = self.handle(*args, **options)
  File "/Users/stan/src/venv_dj_1_7/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/commands/migrate.py", line 160, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/Users/stan/src/venv_dj_1_7/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/db/migrations/executor.py", line 62, in migrate
    self.apply_migration(migration, fake=fake)
  File "/Users/stan/src/venv_dj_1_7/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/db/migrations/executor.py", line 90, in apply_migration
    if self.detect_soft_applied(migration):
  File "/Users/stan/src/venv_dj_1_7/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/db/migrations/executor.py", line 134, in detect_soft_applied
    apps = project_state.render()
  File "/Users/stan/src/venv_dj_1_7/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/db/migrations/state.py", line 71, in render
    raise InvalidBasesError("Cannot resolve bases for %r" % new_unrendered_models)
InvalidBasesError: Cannot resolve bases for [<ModelState: 'parametrage.Support'>, <ModelState: 'parametrage.Commercial'>, <ModelState: 'parametrage.Assistant'>, <ModelState: 'parametrage.Production'>, <ModelState: 'parametrage.Traducteur'>]
make: *** [test] Error 1

I am not using migrations.

Here my models.py:

from django.contrib.sites.models import Site
from django.contrib.auth.models import User


class Support(Site):
    short_name = models.CharField('nom court', max_length=10, unique=True)
    logo = models.ImageField('logo', upload_to='images/supports', blank=True)
    site_ptr = models.OneToOneField(Site, primary_key=True)
    objects = SupportManager()


class Employe(User):
    supports = models.ManyToManyField(Support)
    organisation = models.ForeignKey('Organisation', null=True, blank=True)
    filtre_organisation = models.BooleanField(default=False)
    telephone = models.CharField(u'téléphone', max_length=100, blank=True)

    class Meta:
        abstract = True
        ordering = ('last_name', 'first_name')

    def __unicode__(self):
        return self.get_full_name()

    def supports_txt(self):
        return ', '.join([str(s) for s in self.supports.all()])
    supports_txt.short_description = 'supports'


class Commercial(Employe):
    class Meta:
        verbose_name_plural = 'commerciaux'
        ordering = ('first_name', 'last_name')


class Assistant(Employe):
    class Meta:
        verbose_name = 'chargé de clientèle'
        verbose_name_plural = 'chargés de clientièle'


class Production(Employe):
    class Meta:
        verbose_name = 'chargé de production'
        verbose_name_plural = 'chargés de production'


class Traducteur(Employe):
    pass


Cheers,

Stanislas.

comment:17 by Collin Anderson, 10 years ago

Resolution: fixed
Status: newclosed

It's a separate issue. #22965

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