Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error running code first migration update-database

Im having trouble with my migration to my database and i can't seem to find a answer to the error i am getting

 System.MissingMethodException: Method not found: 'System.Data.Entity.Migrations.Builders.TableBuilder`1 System.Data.Entity.Migrations.Builders.TableBuilder`1.Index(System.Linq.Expressions.Expression`1>, Boolean, Boolean, System.Object)'.
   at Evento.Migrations.initialcreate.Up()
   at System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
   at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)
   at System.Data.Entity.Migrations.DbMigrator.c__DisplayClassc.b__b()
   at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
   at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
   at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
   at System.Data.Entity.Migrations.UpdateDatabaseCommand.c__DisplayClass2.b__0()
   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Method not found: 'System.Data.Entity.Migrations.Builders.TableBuilder`1 System.Data.Entity.Migrations.Builders.TableBuilder`1.Index(System.Linq.Expressions.Expression`1>, Boolean, Boolean, System.Object)'. 
like image 372
Robin Karlsson Avatar asked Mar 25 '14 16:03

Robin Karlsson


People also ask

How do I update my database in migration?

After creating a migration file using the add-migration command, you have to update the database. Execute the Update-Database command to create or modify a database schema. Use the –verbose option to view the SQL statements being applied to the target database.

Which are the to update migration command for update the database in code first approach?

Step 5 − You can create or update the database using the “update-database” command. The "-Verbose" flag specifies to show the SQL Statements being applied to the target database in the console.


2 Answers

I ran into this same issue and here is how I resolved it. I hope this helps someone else.

  1. I deleted Entity Framework from my References and removed the lines from my package.config file(s).
  2. Closed Visual Studio and deleted all the EntityFramework DLL files in my project folders
  3. Opened Visual Studio, then did a Clean and Build
  4. Re-install Entity Framework
  5. Did a Clean and Build again

After that, it was working.

like image 185
L_7337 Avatar answered Oct 09 '22 06:10

L_7337


I ran into this error when running db.Database.Initialize(true);. I discovered that my the console app was referencing EF v 6.0, but the project with the DataContext and ModelBuilder were 6.1.3.

The error went away after setting the console app to 6.1.3 to match the others.

like image 38
Dranyar Avatar answered Oct 09 '22 06:10

Dranyar