0
votes

I'm having problems publishing my MVC project.

I got the error "The model backing the 'ApplicationDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).", that was solved with the help of automigrations.

I published my project via ftp on the another machine, then added some changes on the model`s structure, run it on my computer, it launced succesfull and published again on the same another machine. When I tryed to run it there, an error occurred - "The model backing the 'ApplicationDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269)."

I'm using IIS7 on Windows 7.

2
if you change the model you must update your database with migration - alessandro
How can I update a database located on the computer to which I am referring to ftp? - Devegnik

2 Answers

2
votes

To update database on another Db server you could make this way:

  1. Configure connection string to use new server
  2. Run Update-database command from package manager console, in some cases you will need to use -force flag. But be careful this could delete some your data. Also this command has - ConnectionStringName parameter this could help you to make updates.

This is a very bad approach and I don't recommend update database this way.

I would recommend you set up Initialzier for your context. I usually use MigrateDatabaseToLatestVersion and after changing your model you will need to add new migration, using Add-migration command.

To set up it use this command in application start method:

Database.SetInitializer<ApplicationDbContext>(new MigrateDatabaseToLatestVersion<ApplicationDbContext>());
0
votes

You must update your database after changing the model. Another machine and your computer use the same database? If not you must update this database.