2

I want to update default column value but it seems like default value on columns is is only on the ORM layer, and is not actually setting a default value in the DB and returns error django.db.utils.OperationalError: cannot ALTER TABLE "bps_registration_application" because it has pending trigger events. Is it possible to update default columnn value to 0 in postgress migrations by updating in django model?

This is 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)
prabna
  • 122
  • 2
  • 13
  • yes in django default value on columns is is only on the ORM, so you can add column with allow null and after id edit the migration and add SQL to migration. – Brown Bear Aug 27 '18 at 14:54
  • Possible duplicate of [Django Migrations Add Field with Default as Function of Model](https://stackoverflow.com/questions/29787853/django-migrations-add-field-with-default-as-function-of-model) – Brown Bear Aug 27 '18 at 14:58
  • Can i update default value of existing column without adding new column? – prabna Aug 27 '18 at 15:33
  • yes you can do it by alter table SET/DROP DEFAULT https://www.postgresql.org/docs/9.6/static/sql-altertable.html – Brown Bear Aug 27 '18 at 20:12
  • Possible duplicate of [Django-DB-Migrations: cannot ALTER TABLE because it has pending trigger events](https://stackoverflow.com/questions/12838111/django-db-migrations-cannot-alter-table-because-it-has-pending-trigger-events) – maazza May 17 '19 at 11:01

0 Answers0