It happened to me before.
When the table has been created and I added in .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
later, the code migration somehow could not assign default value for the Guid column.
The fix:
All we need is to go to the database, select the Id column and add newsequentialid()
manually into Default Value or Binding
.
No need to update dbo.__MigrationHistory table.
Hope it helps.
The solution of adding New Guid()
is generally not preferred, because in theory there is possibility that you might get a duplicate accidentally.
And you shouldn't worry about directly editing in the database. All Entity Framework do is automate part of our database work.
Translating
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
into
[Id] [uniqueidentifier] NOT NULL DEFAULT newsequentialid(),
If somehow our EF missed one thing and did not add in the default value for us, just go ahead and add it manually.