简体   繁体   English

EF 核心 3.1 - 从 Mysql 迁移到 PostgreSQL

[英]EF core 3.1 - Migrate from Mysql to PostgreSQL

I am trying to migrate the database, and there is an issue I can't solve.我正在尝试迁移数据库,但有一个我无法解决的问题。 Basically I have to migrate also the existing migrations which are bound to Mysql implementation.基本上我还必须迁移绑定到 Mysql 实现的现有迁移。 Here is one example of the problem:这是问题的一个示例:

 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"

In each migration the same problem throws error and I couln't find in any documentation how do I change this for Postgre.在每次迁移中,相同的问题都会引发错误,我在任何文档中都找不到如何为 Postgre 更改它。 I guess this specifies the Primary Key autogeneration method.我猜这指定了主键自动生成方法。

PS This is the thrown error, because I switched from Pomelo.Mysql to npg.Postgre database provider for ef core: 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

Ok, I figured out an easier way, all migrations including the DataContextModelSnapshot has to be deleted and then a new migration has to be done but, this is only in the case when you want to migrate the schema but not including the data, that has to be done manually好的,我想出了一个更简单的方法,必须删除包括 DataContextModelSnapshot 在内的所有迁移,然后必须进行新的迁移,但是,这仅适用于您想要迁移架构但不包括数据的情况,即手动完成

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM