[Django] #32832: AddField migration of TextField and JSONField fails on Django 3.2.X for MySQL 8.0.19

56 views
Skip to first unread message

Django

unread,
Jun 9, 2021, 2:56:23 PM6/9/21
to django-...@googlegroups.com
#32832: AddField migration of TextField and JSONField fails on Django 3.2.X for
MySQL 8.0.19
-------------------------------------+-------------------------------------
Reporter: Omkar | Owner: nobody
Deshpande |
Type: Bug | Status: new
Component: | Version: 3.2
Migrations | Keywords: django, mysql,
Severity: Normal | textfield, JsonField
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Versions Involved:

Django: 3.2.4
Python: 3.8.7
MySQL: 8.0.19
OS: CentOS 7

----

Referenced:

Ticket: https://code.djangoproject.com/ticket/32503
PR: https://github.com/django/django/pull/14421
Commit:
https://github.com/django/django/pull/14421/commits/5e04e84d67da8163f365e9f5fcd169e2630e2873

----
New project used for reproducing the error:

Project: https://github.com/omkar-dsd/almanac

----

Error:

{{{
django.db.utils.OperationalError: (1101, "BLOB, TEXT, GEOMETRY or JSON
column 'new_txt' can't have a default value")
}}}

Occurred on migration:

{{{
migrations.AddField(
model_name='nucleusdata',
name='new_txt',
field=models.TextField(blank=True, default='abc', null=True),
)
}}}


----

How to reproduce:

1. Add new TextField or JSONField with default on pre-existing model, with
Django < 3.2
2. Upgrade Django version to 3.2.4
3. Run migration which involves creation of of the new field added in step
1.

----

Details:

This occurs for all JSON and Text Fields with default value.

This occurred to me when I upgraded from Django 2.2.24 to 3.2.4 and ran
migrations on fresh DB.
This error did not occur when upgraded from Django 2.2.24 to 3.1.12. And,
it occurs for all 3.2.X till date.
New project was created to demonstrate the issue it available on the above
GitHub link for reference.

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

Django

unread,
Jun 9, 2021, 2:57:47 PM6/9/21
to django-...@googlegroups.com
#32832: AddField migration of TextField and JSONField fails on Django 3.2.X for
MySQL 8.0.19
-------------------------------------+-------------------------------------
Reporter: Omkar Deshpande | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 3.2
Severity: Normal | Resolution:
Keywords: django, mysql, | Triage Stage:
textfield, JsonField | Unreviewed
Has patch: 0 | Needs documentation: 0

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

* Attachment "requirements.txt" added.

Python Project Requirement

Django

unread,
Jun 9, 2021, 2:58:20 PM6/9/21
to django-...@googlegroups.com
#32832: AddField migration of TextField and JSONField fails on Django 3.2.X for
MySQL 8.0.19
-------------------------------------+-------------------------------------
Reporter: Omkar Deshpande | Owner: nobody
Type: Bug | Status: new

Component: Migrations | Version: 3.2
Severity: Normal | Resolution:
Keywords: django, mysql, | Triage Stage:
textfield, JsonField | Unreviewed
Has patch: 0 | Needs documentation: 0

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

* Attachment "models.py" added.

models.py

Django

unread,
Jun 9, 2021, 2:58:44 PM6/9/21
to django-...@googlegroups.com
#32832: AddField migration of TextField and JSONField fails on Django 3.2.X for
MySQL 8.0.19
-------------------------------------+-------------------------------------
Reporter: Omkar Deshpande | Owner: nobody
Type: Bug | Status: new

Component: Migrations | Version: 3.2
Severity: Normal | Resolution:
Keywords: django, mysql, | Triage Stage:
textfield, JsonField | Unreviewed
Has patch: 0 | Needs documentation: 0

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

* Attachment "0001_initial.py" added.

Initial Migration to Create the Table

Django

unread,
Jun 9, 2021, 2:59:06 PM6/9/21
to django-...@googlegroups.com
#32832: AddField migration of TextField and JSONField fails on Django 3.2.X for
MySQL 8.0.19
-------------------------------------+-------------------------------------
Reporter: Omkar Deshpande | Owner: nobody
Type: Bug | Status: new

Component: Migrations | Version: 3.2
Severity: Normal | Resolution:
Keywords: django, mysql, | Triage Stage:
textfield, JsonField | Unreviewed
Has patch: 0 | Needs documentation: 0

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

* Attachment "0002_auto_20210609_1553.py" added.

Second Migration to Alter the fields

Django

unread,
Jun 9, 2021, 2:59:32 PM6/9/21
to django-...@googlegroups.com
#32832: AddField migration of TextField and JSONField fails on Django 3.2.X for
MySQL 8.0.19
-------------------------------------+-------------------------------------
Reporter: Omkar Deshpande | Owner: nobody
Type: Bug | Status: new

Component: Migrations | Version: 3.2
Severity: Normal | Resolution:
Keywords: django, mysql, | Triage Stage:
textfield, JsonField | Unreviewed
Has patch: 0 | Needs documentation: 0

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

* Attachment "0003_nucleusdata_new_txt.py" added.

Third Migration to AddField with default value on which migration breaks

Django

unread,
Jun 9, 2021, 3:01:25 PM6/9/21
to django-...@googlegroups.com
#32832: AddField migration of TextField and JSONField fails on Django 3.2.X for
MySQL 8.0.19
-------------------------------------+-------------------------------------
Reporter: Omkar Deshpande | Owner: nobody
Type: Bug | Status: new

Component: Migrations | Version: 3.2
Severity: Normal | Resolution:
Keywords: django, mysql, | Triage Stage:
textfield, JsonField | Unreviewed
Has patch: 0 | Needs documentation: 0

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

* Attachment "django_AddField_error.txt" added.

Full Error Traceback

Django

unread,
Jun 10, 2021, 12:36:57 AM6/10/21
to django-...@googlegroups.com
#32832: Adding nullable TextField/JSONField with default fails on MySQL 8.0.13+.

-------------------------------------+-------------------------------------
Reporter: Omkar Deshpande | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 3.2
Severity: Release blocker | Resolution:

Keywords: django, mysql, | Triage Stage:
textfield, JsonField | Unreviewed
Has patch: 0 | Needs documentation: 0

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

* cc: Simon Charette, Jordan Bae (added)
* severity: Normal => Release blocker


Comment:

Regression in d4ac23bee1c84d8e4610350202ac068fc90f38c0.
Reproduced at fcd44b889f36c4be87910745614a0a4c88d7a3d8.

We can consider backporting 5e04e84d67da8163f365e9f5fcd169e2630e2873 and
fix it with:
{{{
diff --git a/django/db/backends/base/schema.py
b/django/db/backends/base/schema.py
index c409464eca..77c5ce1629 100644
--- a/django/db/backends/base/schema.py
+++ b/django/db/backends/base/schema.py
@@ -900,7 +900,7 @@ class BaseDatabaseSchemaEditor:

new_db_params =
new_field.db_parameters(connection=self.connection)
if drop:
- if new_field.null:
+ if new_field.null and not
self.skip_default_on_alter(new_field):
sql = self.sql_alter_column_no_default_null
else:
sql = self.sql_alter_column_no_default
}}}

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

Django

unread,
Jun 10, 2021, 12:37:20 AM6/10/21
to django-...@googlegroups.com
#32832: Adding nullable TextField/JSONField with default fails on MySQL 8.0.13+.
-------------------------------------+-------------------------------------
Reporter: Omkar Deshpande | Owner: nobody
Type: Bug | Status: new

Component: Migrations | Version: 3.2
Severity: Release blocker | Resolution:
Keywords: django, mysql, | Triage Stage:
textfield, JsonField | Unreviewed
Has patch: 0 | Needs documentation: 0

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

Comment (by Mariusz Felisiak):

Omkar, thanks for the detailed report!

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

Django

unread,
Jun 10, 2021, 2:11:59 AM6/10/21
to django-...@googlegroups.com
#32832: Adding nullable TextField/JSONField with default fails on MySQL 8.0.13+.
-------------------------------------+-------------------------------------
Reporter: Omkar Deshpande | Owner: nobody
Type: Bug | Status: new

Component: Migrations | Version: 3.2
Severity: Release blocker | Resolution:
Keywords: django, mysql, | Triage Stage: Accepted
textfield, JsonField |
Has patch: 0 | Needs documentation: 0

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

* stage: Unreviewed => Accepted


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

Django

unread,
Jun 10, 2021, 3:08:15 AM6/10/21
to django-...@googlegroups.com
#32832: Adding nullable TextField/JSONField with default fails on MySQL 8.0.13+.
-------------------------------------+-------------------------------------
Reporter: Omkar Deshpande | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned

Component: Migrations | Version: 3.2
Severity: Release blocker | Resolution:
Keywords: django, mysql, | Triage Stage: Accepted
textfield, JsonField |
Has patch: 0 | Needs documentation: 0

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

* owner: nobody => Mariusz Felisiak
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/32832#comment:4>

Django

unread,
Jun 10, 2021, 4:32:53 AM6/10/21
to django-...@googlegroups.com
#32832: Adding nullable TextField/JSONField with default fails on MySQL 8.0.13+.
-------------------------------------+-------------------------------------
Reporter: Omkar Deshpande | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Migrations | Version: 3.2
Severity: Release blocker | Resolution:
Keywords: django, mysql, | Triage Stage: Accepted
textfield, JsonField |
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/14512 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/32832#comment:5>

Django

unread,
Jun 10, 2021, 2:05:44 PM6/10/21
to django-...@googlegroups.com
#32832: Adding nullable TextField/JSONField with default fails on MySQL 8.0.13+.
-------------------------------------+-------------------------------------
Reporter: Omkar Deshpande | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed
Component: Migrations | Version: 3.2
Severity: Release blocker | Resolution: fixed

Keywords: django, mysql, | Triage Stage: Accepted
textfield, JsonField |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"fa0433d05f213afe4c67055006320f7aba4c8108" fa0433d0]:
{{{
#!CommitTicketReference repository=""
revision="fa0433d05f213afe4c67055006320f7aba4c8108"
Fixed #32832 -- Fixed adding BLOB/TEXT nullable field with default on
MySQL 8.0.13+.

Regression in d4ac23bee1c84d8e4610350202ac068fc90f38c0.

Thanks Omkar Deshpande for the report.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32832#comment:6>

Django

unread,
Jun 10, 2021, 2:06:36 PM6/10/21
to django-...@googlegroups.com
#32832: Adding nullable TextField/JSONField with default fails on MySQL 8.0.13+.
-------------------------------------+-------------------------------------
Reporter: Omkar Deshpande | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed
Component: Migrations | Version: 3.2
Severity: Release blocker | Resolution: fixed
Keywords: django, mysql, | Triage Stage: Accepted
textfield, JsonField |
Has patch: 1 | Needs documentation: 0

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

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"826a1659eed0b23f5b814d5a293eeaca20d29a6c" 826a1659]:
{{{
#!CommitTicketReference repository=""
revision="826a1659eed0b23f5b814d5a293eeaca20d29a6c"
[3.2.x] Fixed #32832 -- Fixed adding BLOB/TEXT nullable field with default
on MySQL 8.0.13+.

Regression in d4ac23bee1c84d8e4610350202ac068fc90f38c0.

Thanks Omkar Deshpande for the report.

Backport of fa0433d05f213afe4c67055006320f7aba4c8108 from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32832#comment:7>

Reply all
Reply to author
Forward
0 new messages