Repository: wagtail/wagtail

Issue:
Migration fails on MySQL when upgrading to Wagtail>=2.12rc1
### Issue Summary

The [wagtailembeds.0008_allow_long_urls](https://github.com/wagtail/wagtail/blob/master/wagtail/embeds/migrations/0008_allow_long_urls.py) migration added in 2.12rc1 (https://github.com/wagtail/wagtail/commit/32ade8672fe32223b6ebdcb2255bf4de16908f97) results in the following error on MySQL 8.0 (and presumably also older versions):

    MySQLdb._exceptions.OperationalError:
    (1101, "BLOB, TEXT, GEOMETRY or JSON column 'thumbnail_url' can't have a default value")

This is expected behaviour. According to https://dev.mysql.com/doc/refman/8.0/en/blob.html:

    BLOB and TEXT columns cannot have DEFAULT values.

### Steps to Reproduce
_Update: Migration from 2.11 to 2.12 is not needed; can be reproduced more simply in steps 1–5 using 2.12rc1<=wagtail<=2.12.2_

This issue can be reproduced on a fresh Wagtail project as follows:

1. Install Wagtail ~~< 2.12~~ >= 2.12rc1 with ~~`pip install 'wagtail<2.12'`~~ `pip install 'wagtail>=2.12rc1<=2.12.2'` 
2. Start a new project `wagtail start testproject`
3. Configure the `DATABASES` setting to use a MySQL database
```
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'testproject',
        'USER': 'testuser',
        'PASSWORD': 'testpass'
    }
}
```
4. Prepare the database
```
mysql> create database testproject;
mysql> create user 'testuser'@'localhost' identified by 'testpass';
mysql> grant all privileges on testproject.* to 'testuser'@'localhost';
```
5. Run initial migrations `./manage.py migrate`
~~6. Upgrade to Wagtail 2.12rc1 or greater with, e.g. `pip install --upgrade wagtail==2.12.2`~~
~~7. Re-run migrations `./manage.py migrate`~~

### Additional Notes

Prior to MySQL 8.0.13, BLOB and TEXT could not be assigned DEFAULT values. As of 8.0.13, they can be assigned defaults, but only in the form of expressions as noted in https://dev.mysql.com/doc/refman/8.0/en/data-type-defaults.html#data-type-defaults-explicit

### Technical details
* Python 3.8.3
* Django 3.1.7
* Wagtail 2.11.5 -> 2.12rc1...2.12.2
* MySQL 8.0.21 for osx10.15 on x86_64 (Homebrew)
* mysqlclient 2.0.3


Discussion:
Hi @stvnw,
Thanks for reporting - will investigate further. It seems odd that this error apparently doesn't get triggered when setting up a fresh database on 2.12 ([as our CI tests do](https://github.com/wagtail/wagtail/runs/1925841719?check_suite_focus=true)), despite it running the same sequence of migrations...
Actually it does get triggered on a fresh 2.12 install in my environment as well, so I've edited the original issue slightly. 

I have `STRICT_TRANS_TABLES` enabled on my database (the default) but turning it off doesn't help.

The CI tests are run against MySQL 5.7, so I [tried them](https://github.com/stvnw/wagtail/runs/1987899373) against MySQL 8.0. Interestingly they pass on the Python 3.6 job and fail on the 3.9. Both jobs are using mysqlclient 1.4.6.
Any update for this issue?  Also meet this problem
`django.db.utils.OperationalError: (1101, "BLOB, TEXT, GEOMETRY or JSON column 'thumbnail_url' can't have a default value")`
All works good on wagtail 2.11.3.
Have replicated the issue here on MySQL 8.0.23 on Ubuntu, with Python 3.6.9. Looks like this broke between Django 2.2 and 3.0 (which accounts for the different CI results).

Judging from [this older Django issue](https://code.djangoproject.com/ticket/22424), my understanding is that Django is supposed to abstract away this MySQL-specific detail, in which case I think this would count as a Django bug. Will work further on isolating this as a non-Wagtail test case.
https://github.com/django/django/commit/6b16c91157512587017e9178d066ed1a683e7795 / https://code.djangoproject.com/ticket/30712 appears to be the offending commit.
Issue now opened with Django: https://code.djangoproject.com/ticket/32503

Resolving patch:
diff --git a/wagtail/embeds/migrations/0008_allow_long_urls.py b/wagtail/embeds/migrations/0008_allow_long_urls.py
--- a/wagtail/embeds/migrations/0008_allow_long_urls.py
+++ b/wagtail/embeds/migrations/0008_allow_long_urls.py
@@ -24,13 +24,24 @@ class Migration(migrations.Migration):
             name="url",
             field=models.TextField(),
         ),
+        # Converting URLField to TextField with a default specified (even with preserve_default=False)
+        # fails with Django 3.0 and MySQL >=8.0.13 (see https://code.djangoproject.com/ticket/32503) -
+        # work around this by altering in two stages, first making the URLField non-null then converting
+        # to TextField
         migrations.AlterField(
             model_name="embed",
             name="thumbnail_url",
-            field=models.TextField(
+            field=models.URLField(
                 blank=True,
                 default="",
             ),
             preserve_default=False,
         ),
+        migrations.AlterField(
+            model_name="embed",
+            name="thumbnail_url",
+            field=models.TextField(
+                blank=True,
+            ),
+        ),
     ]


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -125,7 +125,7 @@ jobs:
 
     services:
       mysql:
-        image: mysql:5.7
+        image: mysql:8.0.23
         env:
           MYSQL_ALLOW_EMPTY_PASSWORD: yes
           MYSQL_DATABASE: wagtail