简体   繁体   English

实体框架新表

[英]Entity Framework new table

I updated the project from Entity Framework 5 to 6 and when I start my project a new table is created in the db: dbo.__MigrationHistory . 我将项目从Entity Framework 5更新到了6,当我开始项目时,在db中创建了一个新表: dbo.__MigrationHistory I am using code first and I will guess this is to keep track to the history right? 我首先使用代码,我想这是为了跟踪历史吗?

This was not created there in EF 5. 这不是在EF 5中创建的。

How can I prevent this table to be created? 如何防止创建该表?

when automatic updates run against a database they should apply all changes they can find. 当针对数据库运行自动更新时,它们应应用他们可以找到的所有更改。 There is a system table on the database called migration history that helps with this. 数据库上有一个名为迁移历史记录的系统表可以帮助您解决此问题。 you can manipulate Migration Table but I don't sure that you can disable of creating it. 您可以操纵“迁移表”,但我不确定是否可以禁用创建它。 see this link http://entityframework.codeplex.com/wikipage?title=Migrations%20History%20Table%20Customization 看到此链接http://entityframework.codeplex.com/wikipage?title=Migrations%20History%20Table%20Customization

one of Entity framework specification is Idempotent migrations scripts 实体框架规范之一是幂等迁移脚本

it's obvious that package manager Already Enabled-Migration so you have to disable it using 很明显,程序包管理器已启用迁移,因此您必须使用禁用它

 AutomaticMigrationsEnabled = false;

then set your Initializer 然后设置您的初始化器

Database.SetInitializer<YourContextType>(new CreateDatabaseIfNotExists());

In Entity Framework 5 this table was a system table if the application used Microsoft Sql Server database. 在Entity Framework 5中,如果应用程序使用Microsoft Sql Server数据库,则此表是系统表。 This has changed in Entity Framework 6 这在Entity Framework 6中已更改

Code First needs the Migration History table so you can't remove it, but you can customise it Code First需要“迁移历史记录”表,因此您无法删除它,但是可以自定义它

Reference: Customizing the Migrations History Table 参考: 自定义迁移历史记录表

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM