Say I have an app with this Entity Framework model:
public class Author
{
public int ID { get; set; }
public string Name{ get; set; }
}
public class Context : DbContext
{
public DbSet<Author> Authors{ get; set; }
}
So I do the usual stuff where I run the app, and the initial db schema is created, then enable migrations and update the database.
Now, say I add another property to Author
, string Bio
. I type Add-Migration AddBio
and the appropriate files are generated.
Here's where things getconfusing: I've tried comment everything inside the Up
method of the newly created migration (which is just 1 line for adding a new column, Bio) and do Update-Database
. Now, when I try to add a new author to my database, I get "error occurred, see inner exception for details" message from the runtime.
I realize that this is as a consequence of inconsistencies between the last model snapshot and the database schema (correct me if I'm wrong). The moment I do Add-Migration ...
a new model snapshot is created, and it assumes that Description
is part of the database schema...it's just that it's not.
Is there a way to fix things if I arrive at this sort of situation (I assume this is a very easy way to deliberately confuse someone who's working on a .NET project)? Roll back to the previous migration and then uncomment the code of the latest migration and run it again? Add a (new) migration that will contain the commented out content? Thanks.