【问题标题】:EntityFrameworkCore .net Core update existing database structure without deleting existing dataEntityFrameworkCore .net Core 更新现有数据库结构而不删除现有数据
【发布时间】:2020-07-13 21:12:09
【问题描述】:

有没有办法在不删除 .net core 中现有数据的情况下更新现有数据库结构? 它在.net EF6中工作,但在这个版本中没有 我错过了什么吗?

我只有

命名空间 ProjectTemplate.Contexts { 公共课假人 { [钥匙] 公共指导 ID { 获取;放; }

    [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; }

}

}

并添加了一个属性 public string one { get;放; }

然后它删除整个数据库并创建一个新的:/

【问题讨论】:

    标签: asp.net-core entity-framework-core


    【解决方案1】:

    您是否尝试过使用migrations

    在包管理器控制台中运行:

    add-migration NameOfYourMigration
    

    然后:

    Update-Database
    

    或者,如果您更喜欢使用 CLI:

    dotnet ef migrations add NameOfYourMigration
    

    然后:

    dotnet ef database update
    

    【讨论】:

    • 对不起,我的意思是当结构改变时以编程方式。我们能够在 EF 6 中做到,
    猜你喜欢
    • 2013-06-30
    • 2020-06-15
    • 1970-01-01
    • 1970-01-01
    • 2021-03-20
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多