InvalidBasesError: Cannot resolve bases for []

后端 未结 14 960
遥遥无期
遥遥无期 2021-02-03 23:03

When I run tests I get this error during database initialization:

django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [

        
14条回答
  •  说谎
    说谎 (楼主)
    2021-02-03 23:40

    I also faced this issue (after doing some complex model inheritance). One of my migrations contained

    migrations.CreateModel(
        name='Offer',
        fields=[
            # ...
        ],
        options={
            # ...
        },
        bases=('shop.entity',),
    ),
    

    I deleted shop.Entity model entirely, but the migration was referencing it in bases attribute. So I just deleted bases=('shop.entity',) and it works. It will probably break an opportunity to migrate from the beginning, but at least allows to migrate further on.

    Another advice would be: go directly to django code and inspect what's causing "bases" trouble. Go to django/db/migrations/state.py and add a breakpoint:

    try:
        bases = tuple(
            (apps.get_model(base) if isinstance(base, six.string_types) else base)
            for base in self.bases
        )
    except LookupError:
        print(self.bases)  # <-- print the bases
        import ipdb; ipdb.set_trace()  # <-- debug here
        raise InvalidBasesError("Cannot resolve one or more bases from %r" % (self.bases,))
    

提交回复
热议问题