I created a Code First class
A database was created in Sql automatically.
I deleted the tables :(
I have migrations enabled:
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = true;
Database.SetInitializer(new DropCreateDatabaseAlways<SurveyContext>());
Yet upon
update-database -force
Cannot find the object "dbo.CustomerResponses" because it does not exist or you do not have permissions.
Please help.
Use the Refresh method: context. Refresh(RefreshMode. StoreWins, yourEntity);
In system tables there is a table called
__MigrationHistory
...I deleted it.
In Package manager console ran command "update-database" Problem fixed!
More info:
http://blog.oneunicorn.com/2012/02/27/code-first-migrations-making-__migrationhistory-not-a-system-table/
Daf De Giraf has a better answer here that doesn't wipe out your migration history.
If you worked the correct way to create your migrations by using the command
Add-Migration "Name_Of_Migration"
then you can do the following to get a clean start (reset, with loss of data, of course):
Update-database -TargetMigration:0
Normally your DB is empty now since the down methods were executed.
Update-database
This will recreate your DB to your current migration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With