Django-DB-Migrations: cannot ALTER TABLE because it has pending trigger events

前端 未结 6 1387
梦毁少年i
梦毁少年i 2020-12-02 10:45

I want to remove null=True from a TextField:

-    footer=models.TextField(null=True, blank=True)
+    footer=models.TextField(blank=True, default=\'\')
         


        
6条回答
  •  心在旅途
    2020-12-02 11:35

    You are altering the column schema. That footer column can no longer contain a blank value. There are most likely blank values already stored in the DB for that column. Django is going to update those blank rows in your DB from blank to the now default value with the migrate command. Django tries to update the rows where footer column has a blank value and change the schema at the same time it seems (I'm not sure).

    The problem is you can't alter the same column schema you are trying to update the values for at the same time.

    One solution would be to delete the migrations file updating the schema. Then, run a script to update all those values to your default value. Then re-run the migration to update the schema. This way, the update is already done. Django migration is only altering the schema.

提交回复
热议问题