From 367df5f28d020b6f43b01f6a0382ce5a12e80566 Mon Sep 17 00:00:00 2001 From: Dung Phan Date: Tue, 22 Feb 2022 14:18:50 -0600 Subject: [PATCH] Add support for more data types when adding a new column with default value. --- .../SQLiteMigrationSqlGenerator.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/System.Data.SQLite.EF6.Migrations/SQLiteMigrationSqlGenerator.cs b/System.Data.SQLite.EF6.Migrations/SQLiteMigrationSqlGenerator.cs index 967ad12..98fd6bc 100644 --- a/System.Data.SQLite.EF6.Migrations/SQLiteMigrationSqlGenerator.cs +++ b/System.Data.SQLite.EF6.Migrations/SQLiteMigrationSqlGenerator.cs @@ -196,6 +196,26 @@ private string GenerateSqlStatementConcrete(AddColumnOperation migrationOperatio if (defaultValue.Kind == DateTimeKind.Utc) format += 'Z'; ddlBuilder.AppendSql($" DEFAULT '{defaultValue.ToString(format)}'"); } + else if (column.DefaultValue is bool boolValue) + { + ddlBuilder.AppendSql($" DEFAULT {(boolValue ? 1 : 0)}"); + } + else if (column.DefaultValue is string stringValue) + { + ddlBuilder.AppendSql($" DEFAULT '{stringValue}'"); + } + else if (column.DefaultValue is Guid guidValue) + { + ddlBuilder.AppendSql($" DEFAULT '{guidValue}'"); + } + else if (column.DefaultValue.GetType().IsEnum) + { + ddlBuilder.AppendSql($" DEFAULT {(int)column.DefaultValue}"); + } + else if (column.DefaultValue.GetType().IsValueType) + { + ddlBuilder.AppendSql($" DEFAULT {column.DefaultValue}"); + } } ddlBuilder.AppendNewLine();