1

我有一个继承自两个抽象模型的模型类:

# vehicles app

class Car(
    PolymorphicModel,
    BaseSyncModel,
):
    """Car parent model."""

    id: models.UUIDField = models.UUIDField(  # noqa: A003
        primary_key=True, default=uuid.uuid4
    )
    store: models.ForeignKey = models.ForeignKey(
        CarStores, on_delete=models.CASCADE
    )
    price: models.IntegerField = models.IntegerField()

    year: models.IntegerField = models.IntegerField(
        validators=[MinValueValidator(1900), MaxValueValidator(2021)],
    )
    brand = models.TextField("Car's brand")

它继承自PolymorphicModel和类以进行同步,就像这样:

class BaseSyncModel(models.Model):
    updated_at = models.DateTimeField(auto_now=True, editable=False)

    class Meta:
        abstract = True

我的问题是,当我将它推送到 GitHub 时,CI 引发了以下错误:

django.db.utils.ProgrammingError: column "updated_at" of relation "vehicles_car" does not exist

我认为它与多重继承有关,因为其他不从 PolymorphicModel 继承的类没有引发相同的错误。

我不知道该怎么做。

编辑 - 添加迁移文件

我已经完成了迁移

# Generated by Django 2.2.24 on 2021-07-25 12:53

from django.db import migrations, models


class Migration(migrations.Migration):

   dependencies = [
       ('vehicles', '0010_vehicles_context'),
   ]

   operations = [
       migrations.AddField(
           model_name='motorcycles',
           name='updated_at',
           field=models.DateTimeField(auto_now=True),
       ),
       migrations.AddField(
           model_name='car',
           name='updated_at',
           field=models.DateTimeField(auto_now=True),
       ),
   ]

编辑 2 - 多态模型

这是github上多态模型的链接

编辑 3 - 与多态模型没有关系

我已经从 Car 模型中删除了 Inheritance 并让它只在摩托车模型上并且它引发了同样的错误,但是对于摩托车模型:

django.db.utils.ProgrammingError: column "updated_at" of relation "vehicles_motorcycles" does not exist
4

0 回答 0