验证EF Core ModelSnapshot,迁移和实际数据库架构是否彼此一致 [英] Validate that EF Core ModelSnapshot, migrations, and actual database schema are consistent with each other

查看:834
本文介绍了验证EF Core ModelSnapshot,迁移和实际数据库架构是否彼此一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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.


  • 添加迁移将显示当前模型与模型快照之间的任何差异

  • 脚本迁移将生成一个SQL脚本,您可以使用该脚本从迁移中创建数据库

  • CreateDatabaseScript 将生成一个SQL脚本,您可以使用该脚本从模型中创建数据库

  • SQL Server数据工具可以比较两个数据库

  • Scaffold-DbContext 将创建与数据库兼容的模型

  • Add-Migration will show any differences between your current model and the model snapshot
  • Script-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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆