-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Int32/Int64 properties with default value automatically annotated with SqlServerValueGenerationStrategy.IdentityColumn in migration #5384
Comments
"Identity pattern" is a more general concept in EF that means a value is generated for the property for new entities. For example, your Guid Id property is also setup as Identity in the model, since the values are generated for new entities. This is also true for default values, we need to get the values that was generated back from the database when the row is inserted (more obvious when the default is something like Looks like an issue in migrations, where the presence of a default value means we shouldn't be trying to also use SQL Server |
+1 |
As a workaround for this issue, you should remove the |
…d IdentityColumn configurations Rename ComputedValueSql extension method to ComputedColumnSql to be consistent with fluent API Fixes #5384
…d IdentityColumn configurations Rename ComputedValueSql extension method to ComputedColumnSql to be consistent with fluent API Fixes #5384
After migrating to EF7 RC2 we've noticed that our
int
andlong
properties that are set withHasDefaultValue
in theModelBuilder
are causing the migration script to annotate columns representing those properties with an identity attribute. This, in turn, causes an exception since defaults cannot be created on identity columns.Here's a simplified example of the DbContext:
When creating a migration with Add-Migration, I get the following, which causes an exception when
context.Database.EnsureCreated
is called (Defaults cannot be created on columns with an IDENTITY attribute. Table 'Entitys', column 'Column1'):Is there something I'm missing, or is there a workaround for this?
The text was updated successfully, but these errors were encountered: