Pomelo.EntityFrameworkCore.MySql
Pomelo.EntityFrameworkCore.MySql copied to clipboard
Fail migration instead of complete it with a warning
Hello,
Just to give a little bit of context:
We're using ProxySql that was wrongly configured and reporting its version as 5.5.30-mysql whereas correct version is Mariadb 10.2.31 .
We tried to add a migration to change the default value of a JSON column in the database.
Entity framework generated this migration:
migrationBuilder.AlterColumn<string>(
name: "COLUMN_NAME",
table: "TABLE_NAME",
type: "json",
nullable: true,
defaultValue: "{\"properties\": {\"reported\": {}}}",
oldClrType: typeof(string),
oldType: "json",
oldNullable: true)
.Annotation("MySql:CharSet", "utf8mb4")
.OldAnnotation("MySql:CharSet", "utf8mb4");
The problem is that the migration job "succeeded" but was not applied. We can see it was added to the __EFMigrationHistory table but when we check the table schema the default value is not applied.
Checking the logs we see this:
2023-08-22T12:45:56.818666129Z Starting db migration ...
2023-08-22T12:45:56.818694229Z ################################################################################
2023-08-22T12:45:58.160889532Z Build started...
2023-08-22T12:46:18.938080425Z Build succeeded.
2023-08-22T12:46:19.059272307Z The Entity Framework tools version '6.0.10' is older than that of the runtime '7.0.2'. Update the tools for the latest features and bug fixes. See https://aka.ms/AAc1fbw for more information.
2023-08-22T12:46:21.856107848Z Applying migration '20230717133808_MYMIGRATIONAME'.
2023-08-22T12:46:22.229053407Z The default value ''{"properties": {"reported": {}}}'' is being ignored, because the database server version 5.5.30-mysql does not support constant default values for type 'json' and does not support default
2023-08-22T12:46:22.279578895Z Done.
2023-08-22T12:46:22.306536801Z Cleaning up old migrations configmaps ...
2023-08-22T12:46:22.306576401Z ################################################################################
My question is: How can we disable this to fail the migration instead of skipping it? It is much better to fail a migration so that we can detect the issue sooner rather than completing it without applying it correctly.
This is the log
Steps to reproduce
Add migration to set default value for a JSON column on a Mariadb version that does not support JSON column default values.
Further technical details
MySQL version: 10.2.31-MariaDB-1:10.2.31+maria~bionic Operating system: Linux Pomelo.EntityFrameworkCore.MySql version: 7.0.0 Microsoft.AspNetCore.App version: 6
Other details about my project setup:
Wrongly configured proxysql version it was returning default value.