From 4c99b1d24d66d70de1230454365a3078d851b604 Mon Sep 17 00:00:00 2001 From: Ardiea Date: Fri, 30 Jan 2026 13:01:13 -0500 Subject: [PATCH 1/3] fix: Convert UUIDField columns to uuid type for Mariadb The behavior of the MariaDB backend has changed behavior for UUIDField from a `CharField(32)` to an actual `uuid` type. This is not converted automatically, which results in all writes to the affected columns to error with a message about the data being too long. This is because the actual string being written is a UUID with the `-` included, resulting in a 36 character value which can't be inserted into a 32 character column. --- .../0015_mariadb_uuid_conversion.py | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 cms/djangoapps/contentstore/migrations/0015_mariadb_uuid_conversion.py diff --git a/cms/djangoapps/contentstore/migrations/0015_mariadb_uuid_conversion.py b/cms/djangoapps/contentstore/migrations/0015_mariadb_uuid_conversion.py new file mode 100644 index 000000000000..923b678a31ef --- /dev/null +++ b/cms/djangoapps/contentstore/migrations/0015_mariadb_uuid_conversion.py @@ -0,0 +1,74 @@ +# Generated migration for MariaDB UUID field conversion (Django 5.2) +""" +Migration to convert UUIDField from char(32) to uuid type for MariaDB compatibility. + +This migration is necessary because Django 5 changed the behavior of UUIDField for MariaDB +databases from using CharField(32) to using a proper UUID type. This change isn't managed +automatically, so we need to generate migrations to safely convert the columns. + +This migration only executes for MariaDB databases and is a no-op for other backends. + +See: https://www.albertyw.com/note/django-5-mariadb-uuidfield +""" + +from django.db import migrations + + +def apply_mariadb_migration(apps, schema_editor): + """Apply the migration only for MariaDB databases.""" + connection = schema_editor.connection + + # Check if this is a MariaDB database + if connection.vendor != 'mysql': + return + + # Additional check for MariaDB specifically (vs MySQL) + with connection.cursor() as cursor: + cursor.execute("SELECT VERSION()") + version = cursor.fetchone()[0] + if 'mariadb' not in version.lower(): + return + + # Apply the field changes for MariaDB + with connection.cursor() as cursor: + cursor.execute( + "ALTER TABLE oel_publishing_learningpackage " + "MODIFY uuid uuid NOT NULL" + ) + + +def reverse_mariadb_migration(apps, schema_editor): + """Reverse the migration only for MariaDB databases.""" + connection = schema_editor.connection + + # Check if this is a MariaDB database + if connection.vendor != 'mysql': + return + + # Additional check for MariaDB specifically (vs MySQL) + with connection.cursor() as cursor: + cursor.execute("SELECT VERSION()") + version = cursor.fetchone()[0] + if 'mariadb' not in version.lower(): + return + + # Reverse the field changes for MariaDB + with connection.cursor() as cursor: + cursor.execute( + "ALTER TABLE oel_publishing_learningpackage " + "MODIFY uuid char(32) NOT NULL" + ) + + +class Migration(migrations.Migration): + + dependencies = [ + ('contentstore', '0014_remove_componentlink_downstream_is_modified_and_more'), + ] + + operations = [ + migrations.RunPython( + code=apply_mariadb_migration, + reverse_code=reverse_mariadb_migration, + ), + ] From 60db635dfed715c15e0c2a20b194d496d2368788 Mon Sep 17 00:00:00 2001 From: Ardiea Date: Wed, 11 Feb 2026 11:45:26 -0500 Subject: [PATCH 2/3] fix: renamed migration to 0016 --- ...mariadb_uuid_conversion.py => 0016_mariadb_uuid_conversion.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename cms/djangoapps/contentstore/migrations/{0015_mariadb_uuid_conversion.py => 0016_mariadb_uuid_conversion.py} (100%) diff --git a/cms/djangoapps/contentstore/migrations/0015_mariadb_uuid_conversion.py b/cms/djangoapps/contentstore/migrations/0016_mariadb_uuid_conversion.py similarity index 100% rename from cms/djangoapps/contentstore/migrations/0015_mariadb_uuid_conversion.py rename to cms/djangoapps/contentstore/migrations/0016_mariadb_uuid_conversion.py From 51718d5463f88e3dba65e3121878da561b4fc76d Mon Sep 17 00:00:00 2001 From: Mike Davidson <41908054+Ardiea@users.noreply.github.com> Date: Wed, 11 Feb 2026 13:13:46 -0500 Subject: [PATCH 3/3] Update cms/djangoapps/contentstore/migrations/0016_mariadb_uuid_conversion.py Co-authored-by: David Ormsbee --- .../contentstore/migrations/0016_mariadb_uuid_conversion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cms/djangoapps/contentstore/migrations/0016_mariadb_uuid_conversion.py b/cms/djangoapps/contentstore/migrations/0016_mariadb_uuid_conversion.py index 923b678a31ef..acba91f68370 100644 --- a/cms/djangoapps/contentstore/migrations/0016_mariadb_uuid_conversion.py +++ b/cms/djangoapps/contentstore/migrations/0016_mariadb_uuid_conversion.py @@ -63,7 +63,7 @@ def reverse_mariadb_migration(apps, schema_editor): class Migration(migrations.Migration): dependencies = [ - ('contentstore', '0014_remove_componentlink_downstream_is_modified_and_more'), + ('contentstore', '0015_switch_to_openedx_content'), ] operations = [