I am programming in c# MVC4 asp.net. I keep getting this error when I want to add a new field to the database. I wish i could get help.
The model backing the 'UsersContext' context
has changed since the database was created.
Consider using Code First Migrations to update the database.
What should I do?
Best How To :
You get that error because your database is no longer in sync with your DbContext classes.
You should look into using
You work with code first migrations using the Package Management Console.
Does exactly what the name implies. Initializes migrations in your project. This will create a folder inside your project and generate the files needed.
This creates a migration. InitialCreate is actually a string and you can change it to whatever you want. This command will generate the scripts needed to create the database from strach.
This command verifies the database and applies the migration (or migrations - there can be multiple) required in order to get the database up-to-date.
This is the initial setup. If you do further changes to your first code first classes, or add more, you will just have to add a new migration and then execute it.
It's that simple!
There are some more advanced concepts like seed, rollback, update to specific migration, etc., but what I have typed above covers the basics and the day to day usage of migrations.
I recommend you to read this article which explains everything in much more detail: http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/migrations-and-deployment-with-the-entity-framework-in-an-asp-net-mvc-application