4.30 - Domain Create Error In Plugin

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

I wrote a plugin on 4.30 version. But I have problem in data access when installing.

I create a domain and builder. I want a foreign key in Client Domain From Industry Domain.

Run my plugin and install, after this problem!

An error occured executing the following sql:
ALTER TABLE [dbo].[Sol_B2B_Client] ADD CONSTRAINT [FK_Sol_B2B_Client_IndustryId_Sol_B2B_Industry_Id] FOREIGN KEY ([IndustryId]) REFERENCES [dbo].[Sol_B2B_Industry] ([Id]) ON DELETE CASCADE
The error was Foreign key 'FK_Sol_B2B_Client_IndustryId_Sol_B2B_Industry_Id' references invalid table 'dbo.Sol_B2B_Industry'.
Could not create constraint or index. See previous errors.




public partial class ClientBuilder : NopEntityBuilder<Client>
    {
        #region Methods

        /// <summary>
        /// Apply entity configuration
        /// </summary>
        /// <param name="table">Create table expression builder</param>
        public override void MapEntity(CreateTableExpressionBuilder table)
        {
            table
                .WithColumn(nameof(Client.Name)).AsString(128).NotNullable()
                .WithColumn(nameof(Client.Title)).AsString(250).NotNullable()
                .WithColumn(nameof(Client.MetaTitle)).AsString(400).Nullable()
                .WithColumn(nameof(Client.MetaDescription)).AsString(400).Nullable()
                .WithColumn(nameof(Client.MetaKeywords)).AsString(400).Nullable()
                .WithColumn(nameof(Client.IndustryId)).AsInt32().ForeignKey<Industry>(onDelete: System.Data.Rule.Cascade);
        }

        #endregion
    }


[SkipMigrationOnUpdate]
    [NopMigration("2020/08/19 11:00:00:0000001", "Soluto B2B Core base schema")]
    public class SchemaMigration : AutoReversingMigration
    {
        protected IMigrationManager _migrationManager;

        public SchemaMigration(IMigrationManager migrationManager)
        {
            _migrationManager = migrationManager;
        }

        public override void Up()
        {
            _migrationManager.BuildTable<Client>(Create);
            _migrationManager.BuildTable<Industry>(Create);
            _migrationManager.BuildTable<DiscountClientMapping>(Create);

            //Create.ForeignKey()
            //    .FromTable(nameof(Client)).ForeignColumn(nameof(Client.IndustryId))
            //    .ToTable(nameof(Industry)).PrimaryColumn(nameof(Industry.Id)).OnDelete(Rule.None);

            //Create.ForeignKey()
            //    .FromTable(nameof(PaymentType)).ForeignColumn(nameof(PaymentType.GroupId))
            //    .ToTable(nameof(PaymentTypeGroup)).PrimaryColumn(nameof(PaymentTypeGroup.Id)).OnDelete(Rule.None);

            //Create.ForeignKey()
            //    .FromTable(nameof(PaymentTypeTerm)).ForeignColumn(nameof(PaymentTypeTerm.PaymentTypeId))
            //    .ToTable(nameof(PaymentType)).PrimaryColumn(nameof(PaymentType.Id)).OnDelete(Rule.None);
        }
    }
3 年 前
Did you resolve your issue, if so how?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.