Repository navigation
Description
Summary
Upgrading an existing Ulmo instance to Verawood fails during ./manage.py lms migrate at
openedx_authz.0007_coursescope when the database's default collation is MySQL 8's
utf8mb4_0900_ai_ci (the default on MySQL 8 and on AWS RDS) instead of Tutor's utf8mb4_unicode_ci.
Error
django.db.utils.OperationalError: (3780, "Referencing column 'course_overview_id' and
referenced column 'id' in foreign key constraint
'openedx_authz_course_course_overview_id_e73fe24b_fk_course_ov' are incompatible.")
Environment
- edx-platform
release/verawood, openedx-authz 1.23.0, edx-opaque-keys 4.0.0 - MySQL 8.0.42 on AWS RDS, external DB (Tutor 22.0.2,
RUN_MYSQL=false) - Server / database default collation:
utf8mb4_0900_ai_ci - Long-lived database (first migrations applied in 2021), already fully
utf8mb4
Root cause
- Since opaque-keys 3.1.0 (opaque-keys#426),
OpaqueKeyField.db_parameters()emits an explicit collation on MySQL:
utf8mb4_unicode_ci(orutf8mb4_binwhencase_sensitive=True). - A
ForeignKeycopies the target field'sdb_parameters, so the new
openedx_authz_coursescope.course_overview_idcolumn is created as
varchar(255) COLLATE utf8mb4_unicode_ci. - The existing
course_overviews_courseoverview.idwas created before that change and is
varchar(255) COLLATE utf8mb4_0900_ai_ci. docs: defer authorization implication semantics #426 intentionally generated no migration for
existing columns. - MySQL refuses a FK between varchar columns of different collations, so the migration fails.
Native Tutor installs don't hit this because Tutor's MySQL runs with
--collation-server=utf8mb4_unicode_ci (tutor#1084).
tutor do convert-mysql-utf8mb4-charset does not help here: it refuses to run when
RUN_MYSQL=false and only converts utf8mb3_* collations.
Side effect
MySQL DDL is not transactional: the failed run leaves openedx_authz_coursescope created
but 0007 unrecorded, so the next migrate fails with
(1050, "Table 'openedx_authz_coursescope' already exists") until the table is dropped manually.
Steps to reproduce
- MySQL 8 with default collation
utf8mb4_0900_ai_ci. - Install Ulmo and run migrations (
course_overviews_courseoverview.idgetsutf8mb4_0900_ai_ci). - Upgrade to Verawood and run
./manage.py lms migrate.
Possible fixes (for discussion)
- In
0007_coursescope, createcourse_overview_idwith the collation of the referenced
column as it exists in the database, instead of the one derived from the model. - In opaque-keys, only emit an explicit collation when
case_sensitive=True, or make the
case-insensitive collation configurable by a setting. - At minimum, document in the Verawood release notes that operators whose database default
is notutf8mb4_unicode_cimust aligncourse_overviews_courseoverview.idbefore upgrading.
Related, non-blocking
New columns created with the explicit utf8mb4_unicode_ci collation raise
1267 Illegal mix of collations when compared column-to-column with existing
utf8mb4_0900_ai_ci columns (e.g. edx_when_userdate.first_component_block_id vs
edx_when_contentdate.location). No current code joins those, but the risk will grow
as more such columns are added.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsIn review
- StatusShow more project fieldsIn Review
Activity
bradenmacdonald commentedon Nov 19, 2026
We discussed this in a meeting yesterday: the recommended fix is to update the
CourseScopetable so that it has an integer foreign key to theCourseRuntable, rather than a string foreign key to theCourseOverviewtable. Integer foreign keys do not have collation conflict problems, and will be more efficient than a string key anyways. In fact, nobody should be making foreign keys toCourseOverviewat all going forward, now thatCourseRunis available.However, we don't want
openedx-coreto be a dependency ofopenedx-authz; ratheropenedx-authzshould be a dependency ofopenedx-core. So it might be necessary to move theCourseScopemodel into openedx-core in order to make this work. (Keeping the baseScopeclass in authz.)mariajgrimaldi commentedon Nov 20, 2026
Thanks for sharing! I think the ideal is for the framework not to depend on how scopes are modeled in specific applications, either by not referencing them at all or by providing an interface that applications can implement (which we already offer by subclassing the base scope classes), so moving CourseScope into openedx-core would align with this principle.
For Verawood, I think we're going with the less aggressive approach of keeping the reference to courses through CourseOverview and only fixing 0007 for the installs that are failing, since we want to avoid a breaking change.
For Willow, we can deprecate the CourseOverview reference, and it makes sense to move CourseScope to openedx-core with a foreign key to CourseRun, since that domain owns courses. My proposal for Willow was to drop the foreign key to CourseOverview altogether and reference courses only by their course key, but it's only a proposal for now so we can discuss it in the ADR: #625
What do you think?
bradenmacdonald commentedon Nov 20, 2026
I don't have a strong opinion on those questions, so let's see what others think.
mariajgrimaldi commentedon Nov 27, 2026
This is partially solved for Verawood by: openedx/openedx-platform#39447. We'll be working on a long-term solution for Willow and later releases.