efcore / EFCore.FSharp

Adds F# design-time support to EF Core
MIT License
234 stars 27 forks source link

Scaffolding fails if a column uses a DEFAULT value #145

Open ntwilson opened 2 years ago

ntwilson commented 2 years ago

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:

  1. Create a database table including, e.g., [my_column] [tinyint] NOT NULL DEFAULT 3,
  2. Run dotnet ef dbcontext scaffold on that database
  3. 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):