I just deployed a web application from local host with SQL express (not IIS local host) to production.
The web application has controllers, models, views (MVC). I made some modifications to the database tables. Each time I added a new field I:
enable-migrations
add-migration addnewfieldname
update-database -verbose
All the models get updated with the new table field. The above worked well with my web application on the local host with SQL express.
So then I published it to production with all the migrations. also on production I alter the tables on the database in SQL server to have all the newly created fields.
Now comes the problem, production is not working. what did I do wrong? It gives me error page.
Here is error message:
The model backing the 'DefaultConnection' context has changed since the database was created. Consider using Code First Migrations to update the database
Update
So I found the solution, this is amazing!
First, make sure there are no changes to the UserProfile class. Make sure you are connected to the production db first in your web.config then run:
Enable-Migrations
Add-Migration InitialMigrations -IgnoreChanges
**this below here is key, you need to add the new field one at a time.**
add-migration addnewfield1
update-database
add-migration addnewfield2
update-database
add-migration addnewfield3
update-database
etc.
This should generate a blank "InitialMigration" file. Now, add any desired changes to the UserProfile class. Once changes are added, run the update command again:
update-database -verbose
Now the automatic migration will be applied and the table will be altered with your changes.
Another key, if you don't have permissions on SQL Server to alter tables, make sure you send the scripts to your sysadmin as it won't alter the tables. This is after you have done all the above.