当我运行测试时,我在数据库初始化期间遇到此错误:
django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [<ModelState: 'users.GroupProxy'>]
This can happen if you are inheriting models from an app with migrations (e.g. contrib.auth)
Run Code Online (Sandbox Code Playgroud)
我为contrib.auth Group模型创建了这个代理,将它放在django admin的应用程序中:
class GroupProxy(Group):
class Meta:
proxy = True
verbose_name = Group._meta.verbose_name
verbose_name_plural = Group._meta.verbose_name_plural
Run Code Online (Sandbox Code Playgroud)
那么我该怎么做才能解决这个问题呢?
我正在为模型使用Django 1.7和django-polymorphic
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)
Run Code Online (Sandbox Code Playgroud)
当我运行时makemigrations,出现此错误:
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; …Run Code Online (Sandbox Code Playgroud)