[Django] #32925: TextField default text not populate to MySQL data when migrate

108 views
Skip to first unread message

Django

unread,
Jul 13, 2021, 10:58:11 PM7/13/21
to django-...@googlegroups.com
#32925: TextField default text not populate to MySQL data when migrate
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
GeniusWiki |
Type: Bug | Status: new
Component: Database | Version: 3.2
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/32925>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 13, 2021, 10:59:43 PM7/13/21
to django-...@googlegroups.com
#32925: TextField default text not populate to MySQL data when migrate
-------------------------------------+-------------------------------------
Reporter: Edgenius | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Edgenius:

Old description:

> 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.

New description:

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.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/32925#comment:1>

Django

unread,
Jul 14, 2021, 1:23:57 AM7/14/21
to django-...@googlegroups.com
#32925: TextField default text not populate to MySQL data when migrate
-------------------------------------+-------------------------------------
Reporter: Edgenius | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => invalid


Comment:

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).

--
Ticket URL: <https://code.djangoproject.com/ticket/32925#comment:2>

Django

unread,
Jul 14, 2021, 1:31:57 AM7/14/21
to django-...@googlegroups.com
#32925: TextField default text not populate to MySQL data when migrate
-------------------------------------+-------------------------------------
Reporter: Edgenius | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Edgenius):

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 need some tweak on migration code, but it most like an
inconsistent from django, rather than database limitation.

--
Ticket URL: <https://code.djangoproject.com/ticket/32925#comment:3>

Reply all
Reply to author
Forward
0 new messages