Kyle BC Kyle BC - 3 months ago 17
SQL Question

EF Code First rollback database table design

I accidentally deleted my database tables and I need to get them back. I have tried running

update-database
, but I only get:


Cannot find the object "dbo.ArticleComments" because it does not exist or you do not have permissions.


I also tried running
Update-Database -TargetMigration:"name_of_migration"
with the migration name but resulted in:


Cannot find the object "dbo.ArticleComments" because it does not exist or you do not have permissions.


I need to know how to get my database tables back with their columns (empty or not I don't care)

Answer

This may be the issue on your situation.

check about this problematic table dbo.ArticleComments.If you renamed or deleted it,then it'll give above kind of error.B'cos when you created the old migration script that was there.Now it's not there.When you try to run the same old migration script, now that table is not on your DbSet or having with different name.

Solution :

If that is the case,then you have to manually edit your migration file to reflect the current table changes.