diff --git a/migrations/env.py b/migrations/env.py index 7d4d697..0c5f7bc 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -139,6 +139,20 @@ def run_migrations_online(): pass with connectable.connect() as connection: + # Relax the session sql_mode for the migration run. Some historical + # migrations seed reference rows with raw INSERTs that omit NOT-NULL + # timestamp columns (the ORM supplies those via Python defaults at + # runtime, but a raw migration INSERT does not). MySQL 5.x's lax default + # accepted that; strict MySQL 8 rejects it with 1364 "Field 'createddate' + # doesn't have a default value". Dropping STRICT_TRANS_TABLES for the + # migration session only (the app's own connections keep their mode) + # makes the chain portable across MySQL versions. + try: + connection.exec_driver_sql( + "SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION'") + except Exception: + pass # non-MySQL backends (e.g. sqlite in tests) + context.configure( connection=connection, target_metadata=get_metadata(),