Skip to content

Add support for more data types when adding a new column with default value #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions System.Data.SQLite.EF6.Migrations/SQLiteMigrationSqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down