EntityFrameworkCore .net Core update existing database structure without deleting existing data

asp.net-core entity-framework-core

Question

Is there a way to update existing database structure without deleting existing data in .net core? it was working in .net EF6 but not in this version am i missing something?

All I have is

namespace ProjectTemplate.Contexts { public class Dummy { [Key] public Guid Id { get; set; }

    [Required]
    [Column(TypeName = "nvarchar(50)")]
    public string firstName { get; set; } 

    public int age { get; set; }
    public string otherfield { get; set; }

    public string anotherField { get; set; }

}

}

and added one more property public string one { get; set; }

then it delete the entire database and create a new one :/

1
0
4/2/2020 12:25:46 AM

Popular Answer

Have you tried using migrations?

In the package manager console run:

add-migration NameOfYourMigration

Then:

Update-Database

Or if you prefer to use the CLI:

dotnet ef migrations add NameOfYourMigration

Then:

dotnet ef database update
0
4/2/2020 1:01:23 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow