Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC C# migration from localhost to production
    text
    copied!<p>I just deployed a web application from local host with SQL express (not IIS local host) to production.</p> <p>The web application has controllers, models, views (MVC). I made some modifications to the database tables. Each time I added a new field I:</p> <pre><code>enable-migrations add-migration addnewfieldname update-database -verbose </code></pre> <p>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.</p> <p>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.</p> <p>Now comes the problem, production is not working. what did I do wrong? It gives me error page.</p> <p>Here is error message:</p> <blockquote> <p>The model backing the 'DefaultConnection' context has changed since the database was created. Consider using Code First Migrations to update the database</p> </blockquote> <h2>Update</h2> <p>So I found the solution, this is amazing!</p> <p>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:</p> <pre><code>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. </code></pre> <p>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:</p> <pre><code>update-database -verbose </code></pre> <p>Now the automatic migration will be applied and the table will be altered with your changes.</p> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload