Skip to content
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

Scaffolding fails if a column uses a DEFAULT value #145

Open
ntwilson opened this issue Aug 29, 2022 · 0 comments
Open

Scaffolding fails if a column uses a DEFAULT value #145

ntwilson opened this issue Aug 29, 2022 · 0 comments

Comments

@ntwilson
Copy link

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):

  • OS: Windows 10
  • EntityFrameworkCore.FSharp 6.0.7
  • Microsoft.EntityFrameworkCore 6.0.7
  • dotnet-ef 6.0.7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant