I am trying to create a new plugin for Moneris Payment but I have problems with the database. When trying to install my plugin I have this error : The model backing the 'PluginObjectContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).
If I add the code : Database.SetInitializer<PluginObjectContext>(null); before Database.ExecuteSqlCommand(CreateDatabaseInstallationScript()); it solves this error but the same error appears while trying to insert new data in the table.
I am trying to create a new plugin for Moneris Payment but I have problems with the database. When trying to install my plugin I have this error : The model backing the 'PluginObjectContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).
If I add the code : Database.SetInitializer<PluginObjectContext>(null); before Database.ExecuteSqlCommand(CreateDatabaseInstallationScript()); it solves this error but the same error appears while trying to insert new data in the table.
Does someone have an idea of the solution ?
Thanks.
If you are like many of us, the issue is caused by SQL CE. I usually just switch to SQL Server on my development installation, since nobody is going to use SQL CE on production anyway.
If that's the case, have you make sure that there's no mismatch between your model and the database table? This error also happens when your code cannot map to your database. :)
I solved the problem by adding a class EfStartUpTask in the Data folder. This is the code :
using System.Data.Entity; using Nop.Core.Infrastructure;
namespace Nop.Plugin.Payments.MyPlugin.Data { publicclass EfStartUpTask : IStartupTask { publicvoid Execute() { //It's required to set initializer to null (for SQL Server Compact). //otherwise, you'll get something like "The model backing the 'your context name' context has changed since the database was created. Consider using Code First Migrations to update the database" Database.SetInitializer<MonerisTransactionObjectContext>(null); }
publicint Order { //ensure that this task is run first get { return 0; } } } }