【问题标题】:How to run migration in C#.NET project?如何在 C#.NET 项目中运行迁移?
【发布时间】:2017-03-08 21:58:22
【问题描述】:

我有一个与 SQL Server 一起工作的项目。在Models 目录中,我有一个类似的迁移文件:

public partial class UserData : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.confirmation_code",
                c => new
                    {
                        sys_id = c.Long(nullable: false, identity: true),
                        resource_id = c.Guid(nullable: false),
                        code = c.String(maxLength: 64),
                        user_id = c.Long(nullable: false),
                        id = c.Guid(nullable: false),
                        edit_date = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.sys_id)
                .ForeignKey("dbo.user", t => t.user_id, cascadeDelete: true)
                .Index(t => t.user_id);
....

对于我使用 VisualStudio 的开发,如何运行所有迁移来部署?

【问题讨论】:

    标签: c# .net visual-studio c#-4.0


    【解决方案1】:

    您应该打开 Nuget 管理控制台并键入带有迁移名称的 update-database 命令,如果需要,还可以输入其他参数。根据您的设置,您可能需要提供连接字符串名称和/或它们所在的项目。

    更多信息:Entity Framework Code First Migrations

    【讨论】:

    • 数据库连接的配置通常位于哪个文件中?我使用实体框架
    • 通常在.config 文件中,web.configapp.config
    • 它给了我错误:Specify the '-Verbose' flag to view the SQL statements being applied to the target database. No migrations configuration type was found in the assembly 'WebApplication'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).
    • 那么这意味着您需要使用-ProjectName选项指定带有迁移的项目
    猜你喜欢
    • 2018-02-10
    • 2018-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-07
    • 2020-01-23
    • 2011-03-21
    • 1970-01-01
    相关资源
    最近更新 更多