问题
I am using Django 1.7 and django-polymorphic for my models
class ReferenceItem(PolymorphicModel):
created_at = models.DateTimeField(_('date created'), auto_now_add=True, db_index=True)
updated_at = models.DateTimeField(_('date modified'), auto_now=True, db_index=True)
uuid = UUIDField(auto=True, unique=True)
description = models.CharField(max_length=255)
class OrderItem(ReferenceItem):
order = models.ForeignKey('Order', related_name='items')
sku = models.CharField(max_length=255)
quantity = models.IntegerField()
unit_price = models.DecimalField(max_digits=10, decimal_places=2)
amount = models.DecimalField(max_digits=10, decimal_places=2)
tax_rate = models.DecimalField(max_digits=3, decimal_places=2)
commission_rate = models.DecimalField(max_digits=3, decimal_places=2)
When I ran makemigrations
I got this error:
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: 'orders.OrderItem'>]
This can happen if you are inheriting models from an app with migrations (e.g. contrib.auth)
I have been through the django ticket but still unaware what the problem is.
回答1:
This has got nothing to do with polymorphic package I guess.
What I have done to fix it is to comment out my apps, leaving the builtin django apps, run ./manage.py migrate
to migrate the system apps, then uncomment my apps, and run ./manage.py makemigrations
回答2:
You can also try this:
1) Add a migrations
directory to the problematic app (orders
in this case).
mkdir /path/to/your/app/migrations
2) Add an __init__.py
to that same migrations directory.
touch /path/to/your/app/migrations/__init__.py
3) Run python manage.py makemigrations <yourapp>
4) Migrate any other apps, individually or as a whole, if you are fortunate.
And that should solve it. It's less error prone and hacky than depending on commenting out any installed apps, which isn't really consistent or reproducible.
来源:https://stackoverflow.com/questions/25857169/django-polymorphic-models-having-issues-making-migrations-on-1-7