c# - 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
解决方案
好的,我想出了一个更简单的方法,必须删除包括 DataContextModelSnapshot 在内的所有迁移,然后必须进行新的迁移,但是,这仅适用于您想要迁移架构但不包括数据的情况,即手动完成
推荐阅读
- python - 用于在 Selenium 中读取与切换开关相关的文本标签的 Python 代码
- javascript - 我可以在 JavaScript 中使用 System.Drawing.Color 吗?
- java - 在 Spring 应用程序中使用 JPA 连接多个表时从数据库获取最近更新的结果
- apache-kafka - Kafka 处理器 API,每条处理的记录只有一次语义
- android - 构建一个签名的 Apk
- ios - 使用 pushViewController 时出现“致命错误:在展开可选值时意外发现 nil”
- php - PHP urlencode 返回意外结果
- python - Conda 列表未在虚拟环境中显示包
- javascript - 尝试使用 await 测试使用 mocha 和 chai 获取
- c++ - Clang 和 GCC 中什么级别的优化消除了 noexcept 代码周围的 try-catch?