Plugin development Error : The model backing the 'PluginObjectContext' context has changed since the database was created

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 年 前
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.
11 年 前
rfabre wrote:
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.
11 年 前
No I am already using SQL Server.

Thanks for the suggestion.
11 年 前
rfabre wrote:
No I am already using SQL Server.

Thanks for the suggestion.


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. :)
11 年 前
I have checked again and can't see any difference between the table and my model
11 年 前
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
{
    public class EfStartUpTask : IStartupTask
    {
        public void 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);
        }

        public int Order
        {
            //ensure that this task is run first
            get { return 0; }
        }
    }
}
11 年 前
@rfabre

Thanks for your solution !!! It works perfect !
11 年 前
It also can be caused by a missing property or key mapping in your plugin's EntityMap class or classes
10 年 前
@rfabre

Thank you very much.

The class  "EfStartUpTask : IStartupTask" worked for me, after trying a hundred things dealing with my model class and model mapping :( :(

I think this should be documented somewhere in https://www.nopcommerce.com/docs/75/plugin-with-data-access.aspx

Best regards
10 年 前
This works perfectly - I'm glad this fixes the issue as this is the second time it's happened to me, previously I reinstalled everything.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.