Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#32925 closed Bug (invalid)

TextField default text not populate to MySQL data when migrate

Reported by: Edgenius Owned by: nobody
Component: Database layer (models, ORM) Version: 3.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Edgenius)

When adding 2 new fields, one is CharField and another is TextField, they both nullable with default value:

subject2 = models.CharField(max_length=512, blank=True, null=True, default="Some text")
body2 = models.TextField(blank=True, null=True, default="Some text")

After migration in MySQL 8.0.19, for existing data, new CharField column populate that default "Some text" value. However, TextField is just null. This inconsistent behaviour is very confusing.

Django version is 3.2.5.

Change History (3)

comment:1 by Edgenius, 3 years ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 3 years ago

Resolution: invalid
Status: newclosed

Thanks for the report, unfortunately there is not much we can do. MySQL 8.0.13+ supports BLOB/TEXT defaults (see #30712) but it's really limited (see #32832).

comment:3 by Edgenius, 3 years ago

I doubt if this need to rely on database. It can programatically update this default value to the existing columns when runs migrate. At model.save(), it can save this default value to database. Yes, I understand this needs some tweak on migration code, but it most like an inconsistent from django, rather than database limitation.

Last edited 3 years ago by Edgenius (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top