- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在使用 Entity Framework 6 并且正在使用迁移。我已经使用初始迁移创建了数据库。现在我已经对模型进行了更改并且上下文发生了变化,我想更新数据库但是......当我尝试再次运行 Database-Update
命令时,种子也在运行,并且由于再次插入了一些数据而导致错误。
Update-Database
命令?很难相信 EF 没有像 -No-Seed
这样的简单选项。我几乎可以肯定其他 ORM 确实如此。
最佳答案
来自DbMigrationsConfiguration<TContext>
的源代码:
/// <summary>
/// Runs after upgrading to the latest migration to allow seed data to be updated.
///
/// </summary>
///
/// <remarks>
/// Note that the database may already contain seed data when this method runs. This means that
/// implementations of this method must check whether or not seed data is present and/or up-to-date
/// and then only make changes if necessary and in a non-destructive way. The
/// <see cref="M:System.Data.Entity.Migrations.DbSetMigrationsExtensions.AddOrUpdate``1(System.Data.Entity.IDbSet{``0},``0[])"/>
/// can be used to help with this, but for seeding large amounts of data it may be necessary to do less
/// granular checks if performance is an issue.
/// If the <see cref="T:System.Data.Entity.MigrateDatabaseToLatestVersion`2"/> database
/// initializer is being used, then this method will be called each time that the initializer runs.
/// If one of the <see cref="T:System.Data.Entity.DropCreateDatabaseAlways`1"/>, <see cref="T:System.Data.Entity.DropCreateDatabaseIfModelChanges`1"/>,
/// or <see cref="T:System.Data.Entity.CreateDatabaseIfNotExists`1"/> initializers is being used, then this method will not be
/// called and the Seed method defined in the initializer should be used instead.
///
/// </remarks>
/// <param name="context">Context to be used for updating seed data. </param>
基本上,除了实现“添加或更新”逻辑之外别无选择,因为每次使用初始化程序后都会执行 Seed 方法。
AddOrUpdate 扩展方法对此很有用,但我在某些情况下也使用过它:
if (!context.Entities.Any())
{
// Seed
}
关于c# - EF6 - 运行不带种子的更新数据库命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28635377/
Sequelize 中有没有办法添加另一列,然后用另一列的内容填充它? 最佳答案 您可以使用迁移来做到这一点。 就像是 queryInterface.addColumn( 'MyAwesomeTa
如何计算info_hash参数?又名对应于信息字典的哈希?? 来自官方规范: info_hash The 20 byte sha1 hash of the bencoded form of the i
是否可以直接从数据库或服务等将 URL 获取到 Nutch。我对从数据库或服务获取数据并将其写入 Seed.txt 的方式不感兴趣. 最佳答案 没有。这不能直接使用默认的 nutch 代码库来完成。需
MessageDigest 类实现了 SHA-1 算法(以及许多其他算法)。 SHA-1 算法允许使用不同的“种子”或初始摘要。参见 SHA-1 Psuedocode 算法初始化变量,或种子: Ini
我想创建一个应用程序,其中登录密码可以作为伪随机数生成器的种子以重新创建加密 key 。然后,该加密 key 将用于加密发送到应用程序数据库和从应用程序数据库发送的所有数据,使用户数据甚至主机都无法访
这个问题在这里已经有了答案: Recommended way to initialize srand? (15 个答案) 关闭 8 年前。 使用 srand(time(NULL))似乎过于确定性。例
我在获取要在我的自定义数据库初始值设定项上调用的 Seed 方法时遇到问题。我正在使用 EF 5.0 并具有以下代码: public static class MyDatabase { pub
是否可以像在 Rails 中那样“播种”数据库?我想将种子与图像对象管理器结合使用,以便我可以按标题获取记录。 最佳答案 根据您对 Ingo 的回答留下的评论,您想将 requireDefaultRe
我现在设置了一个应用程序来使用 EF6 代码优先迁移。我使用 Add-Migration 的标准工作流程,然后在控制台中使用 Update-Database。我在本地以及我们的开发环境中使用 Migr
如果 Name 返回然后删除 first name Name john Age 30 Name Alice Name Travis Age 12 Name Monty Name Hannah 期望的输
在迁移完成后,是否可以在我的迁移中放入一些东西来自动为表播种测试数据? 或者您必须单独播种? 最佳答案 您可以使用 --seed 选项调用 migrate:refresh 以在迁移完成后自动播种: p
我正在尝试使用不同的种子生成 scipy.stats.pareto.rvs(b, loc=0, scale=1, size=1)。 在 numpy 中,我们可以使用 numpy.random.seed
我的种子有问题。这是我的表结构: 1.Complaints: Schema::create('complaints', function (Blueprint $table) {
我在使用数据库初始化程序时遇到问题 - 从未调用过种子方法。类似的代码在另一个项目中工作,所以我很困惑为什么他们这次不工作。 这是我的代码: RecipeContext.cs public c
我正在尝试做一些我认为非常简单的事情,只需使用 RAND 创建 0-1 之间的随机数,并将其分配给十进制变量。但每次我在 MySQL 中运行代码时,它都会返回零! 参见下面的代码: DELIMITER
我有一个问题...... 这里我们得到了一个二维字节数组: byte[][] duengonMap = new byte[500][500]; 因为我想将它从客户端发送到服务器或者相反,我需要将其放入
我尝试在我的计算机上运行 Angular-seed(Windows 10,上次更新)https://github.com/angular/angular-seed 。网络工作正常,但我的 Protra
我有一个随机过程的分布式过程。因此,我使用 numpy.random.RandomState 来播种数字。问题是我必须在包装器中使用另一个 numpy.random 函数。现在我失去了种子的再现性,因
我需要确保我程序中的所有随机性都是完全可复制的。我应该在哪里调用 random.seed()? 我认为它应该在我的 main.py 模块中,但它导入了碰巧使用随机函数的其他模块。 我可以仔细浏览我的导
首先尝试使用 Entity Framework 和代码在 ASP.NET 网络应用程序中植入数据。我将这段代码放在 Configuration.cs 文件的 Seed() 方法中。现在,我正在处理解决
我是一名优秀的程序员,十分优秀!