When I run tests I get this error during database initialization:
django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [
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,))
Having spent the majority of this afternoon trying to solve this error myself, going through every conceivable mixture of 'commenting out apps', 'dropping tables' and dropping entire databases I found that my issue was caused by a simple lack of a 'migrations' folder and an __ init__.py file inside of said folder.
One of the older answers which was correct is now no longer correct as they have fixed the issue mentioned here.
Check every directory that contains the model mentioned in 'init.py' and it should go away.
Probably won't solve everyone's case but it helped mine.
One possibility is that the deleting or creating of a model in the migration file is in the wrong order. I experienced this in Django 1.7.8 when the base model was BEFORE the derived model. Swapping the order for deleting the model fixed the issue.
Just incase anyone made the same mistake as me, I had the same issue because I hadn't made any migrations for the Proxy models. It didn't seem necessary to me as they don't have their own DB tables and I didn't see anything mentioning this in the docs. python manage.py makemigrations <APP_NAME>
fixed it right up.
Have you tried running manage.py makemigrations <app_label>
on your app before running tests?
Also, check if the app which model(s) you are trying to Proxy is included in your INSTALLED_APPS.
If this occurs to you in an app that already has a migrations folder (and a init.py file in it), delete all other files, and run makemigrations
and migrate
again.
P.S.: You may need to reconfigure your models.py or some tables in your database manually.