You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm adding a non nullable string property to an existing and it forces the default value to be ''
However, if I'm creating a table from scratch (with the property), there is no default value.
There are two issue with this:
.HasDefaultValue(null) doesn't work, and this is no .DisableDefaultValue()
You database schema could different depending in the migration path you took.
It is also awkward to remove the default value,
I generally try to avoid modifying generated add migration code.
The only "pure cli way" i can find is to add a migration .HasDefaultValue('') and then add another removing .HasDefaultValue('')
this works.... (is there a better way?)
Include your code
usingMicrosoft.EntityFrameworkCore;Console.WriteLine("Welcome");/* steps * dotnet ef migrations add InitialCreate * Uncomment //public string Name { get; set; } in ExampleEvolution * dotnet ef migrations add AddRequiredNamePropertyAfterTableCreationNotice: Observe ExampleTable & ExampleEvolution are the same ExampleTable.Name has no default value ExampleEvolution.Name has a default Value: '' */publicclassBloggingContext:DbContext{publicDbSet<ExampleTable>ExampleTable{get;set;}publicDbSet<ExampleEvolution>ExampleEvolution{get;set;}protectedoverridevoidOnConfiguring(DbContextOptionsBuilderoptions)=>options.UseSqlServer($"");}publicclassExampleTable{publicintId{get;set;}publicstringName{get;set;}}publicclassExampleEvolution{publicintId{get;set;}// uncomment for second migration// public string Name { get; set; }}
The text was updated successfully, but these errors were encountered:
I'm adding a non nullable string property to an existing and it forces the default value to be ''
However, if I'm creating a table from scratch (with the property), there is no default value.
There are two issue with this:
.HasDefaultValue(null) doesn't work, and this is no .DisableDefaultValue()
You database schema could different depending in the migration path you took.
It is also awkward to remove the default value,
I generally try to avoid modifying generated add migration code.
The only "pure cli way" i can find is to add a migration .HasDefaultValue('') and then add another removing .HasDefaultValue('')
this works.... (is there a better way?)
Include your code
The text was updated successfully, but these errors were encountered: