How to recreate my EF CodeFirst Table?

I created a Code First class

The database was created in Sql automatically.

I deleted the tables :(

I have migration enabled:

AutomaticMigrationsEnabled = true; AutomaticMigrationDataLossAllowed = true; Database.SetInitializer(new DropCreateDatabaseAlways<SurveyContext>()); 

Nevertheless

 update-database -force Cannot find the object "dbo.CustomerResponses" because it does not exist or you do not have permissions. 

Please, help.

+8
entity-framework code-first
source share
3 answers

The system tables have a table called

 __MigrationHistory 

... I deleted it.

The command "update-database" is running in the package manager console. The problem is fixed!

Additional Information:

http://blog.oneunicorn.com/2012/02/27/code-first-migrations-making-__migrationhistory-not-a-system-table/

+7
source share

Daf De Giraf has a better answer here that will not erase your migration history.

If you worked correctly to create your migrations using the Add-Migration "Name_Of_Migration" , then you can do it to get a clean start (reset, with data loss, of course ):

  • Update-database -TargetMigration:0
    Usually your database is empty because the down methods were executed.

  • Update-database This will restore your database to the current migration.

+2
source share

I had this error message in the past ....

Check if the database specified in the connection string is created. If it is not, create it and then execute the code.

0
source share

All Articles