Entity Framework 6 - Does not create tables when enabling Migrations

拟墨画扇 提交于 2019-11-30 20:30:39

I don't know that this is EntityFramework's bug or not, but when I made rename the namespace of Migration Configuration class from default (Projectname/Migrations) to any none default name, migration works well.

Context.Database.Create() will not execute migrations! It only creates empty db. To Update database from code to latest version you need to use DbMigrator.Update method:

var migrator = new DbMigrator(new MyMigrationsConfiguration());
migrator.Update();

Alternatively you might use MigrateDatabaseToLatestVersion

Database.SetInitializer(new MigrateDatabaseToLatestVersion<BlogContext, Configuration>());

It is described in details here: http://msdn.microsoft.com/en-us/data/jj591621.aspx#initializer

nad sid

It does happens when adding model and running add-migration command.

Here is the simplest cause of this issue:

Add a newly added model property into IdentityDbContex class.

Here are the steps:

  1. create model
  2. add property into IdentityDbContex class
  3. run add-migration
  4. update-database
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!