how can i update a plugin?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
I created a plugin as v1.0. Now that I have added more stuff to the plugin and additional columns in the plugin table. How can I update the plugin on site that is running my plugin v1.0?

In my test solution when i try to install the plugin v2.0 (after uninstalling v1.0), i get this error-

"The model backing the 'MyDbContext' context has changed since the database was created"

What can i do to make the v2.0 work (install) with no error and what can i do to update the plugin on site running my plugin v1.0?

What i don't understand is that when uninstalling my plugin v1.0 also deleted the database table and v2.0 should create new tables in database why it will still reference old plugin model?

What and where is the 'MyDbContext' and it keeps the old plugin stuff?

If someone can explain this for my understanding and provide solution would be appreciated
7 years ago
robbyr wrote:
"The model backing the 'MyDbContext' context has changed since the database was created"


It is because of migration

You need to set the database initializer in the context class:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {

        base.OnModelCreating(modelBuilder);
    }


Or else find migration table created under system table __MigrationHistory, and delete it.
7 years ago
thanks

If I add that code in the Plugin then I won't get the error?

If I delete the entry of old plugin v1.0 from the migration database table then I can install v2.0 without making changes in the code?


What about the sites that are using my plugin v1.0 because installing or deleting tables is not an option due to production data? I was thinking running a SQL script on v1.0 Plugin tables in DB to add additional columns but that will only take care of database table not the updated model. What to do then?
7 years ago
robbyr wrote:
If I add that code in the Plugin then I won't get the error?

Yes, as per my knowledge!
http://stackoverflow.com/questions/3600175/the-model-backing-the-database-context-has-changed-since-the-database-was-crea  
  

robbyr wrote:

If I delete the entry of old plugin v1.0 from the migration database table then I can install v2.0 without making changes in the code?

Yes, as per my knowledge!
http://stackoverflow.com/a/30433075/4753489

robbyr wrote:

What about the sites that are using my plugin v1.0 because installing or deleting tables is not an option due to production data? I was thinking running a SQL script on v1.0 Plugin tables in DB to add additional columns but that will only take care of database table not the updated model. What to do then?


I haven't said to delete your actual plugin table. if you update it manually, then do not worry about model, because it'll match with database fields.
7 years ago
Divyang wrote:
[b]

Or else find migration table created under system table __MigrationHistory, and delete it.


Yes you are right. I can see a row with my plugin name in this table.

So am I deleting this table or just the row with my plugin entry to fix contextkey error?
7 years ago
robbyr wrote:
So am I deleting this table or just the row with my plugin entry to fix contextkey error?


You can delete your plugin entry, even though DELETE FROM [dbo].[__MigrationHistory] will not cause any issue.
7 years ago
Deleting the row is still showing an error

There is already an object named '__MigrationHistory' in the database.

In my case dropping the table '__MigrationHistory' helped. If i add "drop this table" on plugin v1.0 uninstall event, will it be a OK?
7 years ago
robbyr wrote:
If i add "drop this table" on plugin v1.0 uninstall event, will it be a OK?

Migrations history table is a table used by Code First Migrations to store details about migrations applied to the database. Drop table wouldn't be a proper way. How to handle it from code(OnModelCreating) that what is stated in my first post.

Hope this helps!
7 years ago
Hi I am not using plugin creation approach as describe in Nopcommerce.
I am using simple code first approach in plugin creation and not able to use that method on model creating.
Can you please describe any other way where we need not to delete migration table and can update plugin.
7 years ago
harshitporwal wrote:
Hi I am not using plugin creation approach as describe in Nopcommerce.
I am using simple code first.


nopCommerce described approach is code first only.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.