首页 > 解决方案 > EF core 3.1 - 从 Mysql 迁移到 PostgreSQL

问题描述

我正在尝试迁移数据库,但有一个我无法解决的问题。基本上我还必须迁移绑定到 Mysql 实现的现有迁移。这是问题的一个示例:

 migrationBuilder.CreateTable(
                name: "AspNetUserClaims",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    UserId = table.Column<string>(nullable: false),
                    ClaimType = table.Column<string>(nullable: true),
                    ClaimValue = table.Column<string>(nullable: true)
                },
"MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn"

在每次迁移中,相同的问题都会引发错误,我在任何文档中都找不到如何为 Postgre 更改它。我猜这指定了主键自动生成方法。

PS 这是抛出的错误,因为我从 Pomelo.Mysql 切换到 ef 核心的 npg.Postgre 数据库提供程序:

Error   CS0103  The name 'MySqlValueGenerationStrategy' does not exist in the current context   BingoAPI    D:\Bingo\BingoAPI\Migrations\20200420230201_IdentityUser.cs 76  Active

标签: c#mysqlpostgresqlasp.net-coreentity-framework-core

解决方案


好的,我想出了一个更简单的方法,必须删除包括 DataContextModelSnapshot 在内的所有迁移,然后必须进行新的迁移,但是,这仅适用于您想要迁移架构但不包括数据的情况,即手动完成


推荐阅读