Adding New Property to existing entity

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
2 年 前
Hi,

Through the official nop-commerce docs I followed the steps of adding an existing column to the Catalog Entity , but I have no clue on how to run the migrations so the existing catalog db is updated with the new column "SomePropertyName"
2 年 前
If you followed this document then you should get everything on the documentation.
https://docs.nopcommerce.com/en/developer/tutorials/update-existing-entity.html
2 年 前
I followed the documentation it said use your own custom sql script or nopcommerce Installation. I navigated to /install url and it only yielded error for me. I am not sure how to re run the installation now.
2 年 前
alex-dhanasekar wrote:
use your own custom sql script.

Here is the example SQL Script
ALTER TABLE [dbo].[Category]
ADD [AddSomeNewProperty ] [nvarchar](255) NULL
2 年 前
Alter script is fine, but since we are using fluent migrator for the db migration , I was expecting fluent migrator commands or some installation process in our nopcommerce application to do the migrations. Do we have any other options apart from running direct alter scripts?
2 年 前
alex-dhanasekar wrote:
I followed the documentation it said use your own custom sql script or nopcommerce Installation. I navigated to /install url and it only yielded error for me. I am not sure how to re run the installation now.

For re run just delete datasettings.json & plugins.json. or remove your plugin name from plugins.json and run again and check error from admin ->system->log and fix the error
2 年 前
Found out the actual issue, in the nopCommerce documentation the code was a little bit wrong,
The NopMigration Attribute in

public class AddSomeNewProperty: AutoReversingMigration should be given as :
[NopMigration("2021/12/19 11:24:16:2551770", "Category. Add some new property", UpdateMigrationType.Data, MigrationProcessType.Update)]

Instead of

[NopMigration("2020/05/25 11:24:16:2551770", "Category. Add some new property", MigrationProcessType.Installation)]

Ignore the date mentioned in the attribute, the error is "MigrationProcessType.Installation" it should be given as "MigrationProcessType.Update" and the migration runner automatically takes care of the update you dont have to run any custom scripts
2 年 前
This was a bit confusing - This is what worked for me as I was not using AutoReversing

namespace Nop.Plugin.Name.Group.Data.Migrations.UpgradeTo440
{
    [NopMigration("2022/01/09 11:24:16:2551770", "Add some new property", UpdateMigrationType.Data)]
    public class UpdateTo440 : FluentMigrator.Migration
    {

        /// <summary>
        /// Collect the UP migration expressions
        /// </summary>
        public override void Up()
        {
            var tableName = NameCompatibilityManager.GetTableName(typeof(TableName));
            //add column
            var columnName = "ColumnName";

            if (!Schema.Table(tableName).Column(columnName).Exists())
            {
                Alter.Table(tableName)
                    .AddColumn(columnName).AsBoolean().NotNullable().SetExistingRowsTo(false);
            }
        }

        /// <summary>
        /// Collect the Down migration expressions
        /// </summary>
        public override void Down()
        {
        }

    }
}
2 年 前
Hi, @alex-dhanasekar. Thank you, we have updated the documentation, here is a link to the relevant page.
alex-dhanasekar wrote:
Found out the actual issue, in the nopCommerce documentation the code was a little bit wrong,
The NopMigration Attribute in

public class AddSomeNewProperty: AutoReversingMigration should be given as :
[NopMigration("2021/12/19 11:24:16:2551770", "Category. Add some new property", UpdateMigrationType.Data, MigrationProcessType.Update)]

Instead of

[NopMigration("2020/05/25 11:24:16:2551770", "Category. Add some new property", MigrationProcessType.Installation)]
2 年 前
Hi Dimitry,
Thanks for the update! That helps!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.