将默认值为0的Django字段迁移到PostgreSQL数据库

时间:2018-08-27 14:48:15

标签: python django

我想更新默认列值,但似乎列上的默认值仅在ORM层上,并且实际上未在DB中设置默认值并返回错误django.db.utils.OperationalError:不能更改表“ bps_registration_application”,因为它具有未决的触发事件。通过在Django模型中进行更新,是否可以在postgress迁移中将columnn的默认值更新为0?

这是models.py。

class Application(models.Model):
    registration_date = models.CharField(max_length=15)
    building_use = models.ForeignKey(to=system_settings.models.BuildingUse)
    building_category = models.CharField(max_length=30)
    building_structure_category = models.ForeignKey(to=system_settings.models.BuildingStructureCategory)
    building_length_ft = models.IntegerField(blank=True,  default=0)
    building_breadth_ft = models.IntegerField(blank=True,  default=0)
    building_height_ft = models.IntegerField(blank=True, default=0)
    building_length_in = models.IntegerField(blank=True,  default=0)
    building_breadth_in = models.IntegerField(blank=True,  default=0)
    building_height_in = models.IntegerField(blank=True,  default=0)

    building_storey = models.IntegerField(blank=True,  default=0)
    building_area = models.DecimalField(max_digits=6, decimal_places=2)

    reg = models.ForeignKey(NewRegistration)

0 个答案:

没有答案