验证 EF Core ModelSnapshot、迁移和实际数据库架构彼此一致 [英] Validate that EF Core ModelSnapshot, migrations, and actual database schema are consistent with each other
问题描述
我正在使用 EF Core.在巧妙地"合并了几个引入迁移的源代码控制分支之后,我不再相信我的 ModelSnapshot
与我的迁移或我的实际数据库一致.
I am using EF Core. After "cleverly" merging a couple of source control branches that both introduced migrations, I'm no longer confident that my ModelSnapshot
is consistent with either my migrations or my actual database.
是否有一些命令或函数可以用来验证三者是否一致(即快照是当前数据库模式的忠实表示,以及迁移,当应用于新创建的数据库时,会生成那个架构)?
Is there some command or function that I can use to validate that the three are consistent with each other (i.e. that the snapshot is a faithful representation of the current database schema and that the migrations, when applied to a newly-created database, will generate that schema)?
推荐答案
您可以使用以下工具进行一些完整性检查.
Here are tools you can use to perform some sanity checks.
Add-Migration
将显示您当前模型和模型快照之间的任何差异Script-Migration
将生成一个 SQL 脚本,您可以使用它从迁移中创建一个数据库- CreateDatabaseScript 将生成一个 SQL 脚本,您可以使用它从模型
- SQL Server Data Tools 可以比较两个数据库
Scaffold-DbContext
将创建一个与数据库兼容的模型
Add-Migration
will show any differences between your current model and the model snapshotScript-Migration
will produce a SQL script you can use to create a database from the migrations- CreateDatabaseScript will produce a SQL script you can use to create a database from the model
- SQL Server Data Tools can compare two databases
Scaffold-DbContext
will create a model that is compatible with a database
这篇关于验证 EF Core ModelSnapshot、迁移和实际数据库架构彼此一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!