Describe the bug
If a column in your database is defined with a DEFAULT supplied by the schema, the code generated by dotnet ef dbcontext scaffold will include both .HasDefaultValueSql (with the DEFAULT supplied by the schema) and HasDefaultValue (with the regular default applied to all normal columns). This causes an exception when trying to execute the project:
System.InvalidOperationException: DefaultValue cannot be set for 'my_column' at the same time as DefaultValueSql. Remove one of these configurations.
To Reproduce
Steps to reproduce the behavior:
Create a database table including, e.g., [my_column] [tinyint] NOT NULL DEFAULT 3,
Run dotnet ef dbcontext scaffold on that database
Try to create a dbcontext object and run it to observe the runtime exception
Expected behavior
The normally generated .HasDefaultValue should be omitted if there's already a .HasDefaultValueSql configuration specified.
Desktop (please complete the following information):
Describe the bug If a column in your database is defined with a DEFAULT supplied by the schema, the code generated by
dotnet ef dbcontext scaffold
will include both.HasDefaultValueSql
(with the DEFAULT supplied by the schema) andHasDefaultValue
(with the regular default applied to all normal columns). This causes an exception when trying to execute the project:To Reproduce Steps to reproduce the behavior:
[my_column] [tinyint] NOT NULL DEFAULT 3,
dotnet ef dbcontext scaffold
on that databaseExpected behavior The normally generated
.HasDefaultValue
should be omitted if there's already a.HasDefaultValueSql
configuration specified.Desktop (please complete the following information):