简体   繁体   English

每次使用Entity Framework更新数据库时如何创建新迁移

[英]How do I create a new migration each time I update the database with Entity Framework

In my dbo.__MigrationHistory table from my Entity Framework database I have 3 entries: 在我的Entity Framework数据库的dbo.__MigrationHistory表中,我有3个条目:

201708082015111_InitialCreate 
201708082017162_Initial
201708082046380_AutomaticMigration

but in the project itself, I have just one migration file: 但是在项目本身中,我只有一个迁移文件:

201708082017162_Initial.cs

I was thinking to delete the database and start over. 我正在考虑删除数据库并重新开始。

My main focus is how to create migration files each time I update the database from package console. 我的主要重点是每次从程序包控制台更新数据库时如何创建迁移文件。 For example, I create another model (therefore, another entity in my schema), so I want to run Update-Database and create a migration file in C# at the same time containing information about the updated schema (with the new table...). 例如,我创建了另一个模型(因此在我的架构中是另一个实体),因此我想运行Update-Database并同时在C#中创建一个迁移文件,其中包含有关更新的架构的信息(以及新表...) )。

因此,我通过应用以下程序使其工作: Add-Migration migx ,然后运行Update-Database -verbose然后,我检查了__MigrationHistory表,并注意到已应用201708082108002_migx。

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

相关问题 使用实体框架在 .NET Core 3.1 中进行迁移后,如何更新数据库 model? - How can I update the database model after doing a migration in .NET Core 3.1 using Entity Framework? 如何使用实体框架6数据上下文创建数据库? - How do I create database using entity framework 6 datacontext? 如何使用Entity Framework 4.2执行数据库迁移? - How can I perform database migration using Entity Framework 4.2? 如何在实体框架 6 中为 SQL 查询创建迁移? - How I can create migration for SQL queries in Entity Framework 6? 如何在命令行上更改连接字符串以在迁移到Entity Framework Core中的新数据库时更新数据库 - How to change connection string on command line to update database on migration to a new database in Entity Framework Core 实体框架 - 如何正确更新? - Entity Framework - how do I update correctly? 实体框架代码优先迁移始终尝试创建新数据库 - Entity framework code first migration always tries to create new database 实体框架不会创建新的迁移:数据库名称无效 - Entity Framework does not create a new migration: database name is invalid 如何使用没有迁移历史记录的实体框架更新数据库 - How to update database using entity framework without migration history 如何在实体框架中创建只读实体? - How do I create a read only entity in the entity framework?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM