Foreign Key Violation Error when creating a new Product Variant

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
15 years ago
I[b] am using the new version of nopCommerce Framework i.e ver.1.10. When I try to add a new product variant under a product it gives me the following error:[/b]

T[color=red]he INSERT statement conflicted with the FOREIGN KEY constraint "FK_Nop_ProductVariant_Nop_LowStockActivity". The conflict occurred in database "RedBellStore", table "dbo.Nop_LowStockActivity", column 'LowStockActivityID'. The statement has been terminated. [/color]

System.Data.SqlClient.SqlException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Nop_ProductVariant_Nop_LowStockActivity". The conflict occurred in database "RedBellStore", table "dbo.Nop_LowStockActivity", column 'LowStockActivityID'. The statement has been terminated. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Microsoft.Practices.EnterpriseLibrary.Data.Database.DoExecuteNonQuery(DbCommand command) at Microsoft.Practices.EnterpriseLibrary.Data.Database.ExecuteNonQuery(DbCommand command) at NopSolutions.NopCommerce.DataAccess.Products.SQLProductVariantProvider.InsertProductVariant(Int32 ProductID, String Name, String SKU, String Description, String AdminComment, String ManufacturerPartNumber, Boolean IsDownload, Int32 DownloadID, Boolean IsShipEnabled, Boolean IsFreeShipping, Boolean IsTaxExempt, Int32 TaxCategoryID, Int32 StockQuantity, Int32 MinStockQuantity, Int32 LowStockActivityID, Int32 WarehouseId, Boolean DisableBuyButton, Boolean RequiresTextOption, String TextOptionPrompt, Decimal Price, Decimal OldPrice, Decimal Weight, Decimal Length, Decimal Width, Decimal Height, Int32 PictureID, Boolean Published, Boolean Deleted, Int32 DisplayOrder, DateTime CreatedOn, DateTime UpdatedOn) in D:\Work\Own\NopCommerce\Solution\NopCommerce\Nop.DataAccess.SqlServer\Products\SQLProductVariantProvider.cs:line 181 at NopSolutions.NopCommerce.Common.Products.ProductVariantManager.InsertProductVariant(Int32 ProductID, String Name, String SKU, String Description, String AdminComment, String ManufacturerPartNumber, Boolean IsDownload, Int32 DownloadID, Boolean IsShipEnabled, Boolean IsFreeShipping, Boolean IsTaxExempt, Int32 TaxCategoryID, Int32 StockQuantity, Int32 MinStockQuantity, LowStockActivityEnum LowStockActivity, Int32 WarehouseId, Boolean DisableBuyButton, Boolean RequiresTextOption, String TextOptionPrompt, Decimal Price, Decimal OldPrice, Decimal Weight, Decimal Length, Decimal Width, Decimal Height, Int32 PictureID, Boolean Published, Boolean Deleted, Int32 DisplayOrder, DateTime CreatedOn, DateTime UpdatedOn) in D:\Work\Own\NopCommerce\Solution\NopCommerce\Nop.Common\Products\ProductVariantManager.cs:line 310 at NopSolutions.NopCommerce.Web.Administration.Administration_ProductVariantAdd.SaveButton_Click(Object sender, EventArgs e) in c:\NopCommerce\NopCommerceWeb\Administration\ProductVariantAdd.aspx.cs:line 122

Any help by the moderators or users of the site would be greatly appreciated.
Thanks!
15 years ago
Look at your [Nop_LowStockActivity] table. It need to by sync with the below enum:

/// <summary>
    /// Represents a low stock activity (need to be synchronize with [Nop_LowStockActivity] table
    /// </summary>
    public enum LowStockActivityEnum : int
    {
        /// <summary>
        /// Nothing
        /// </summary>
        Nothing = 0,
        /// <summary>
        /// Disable buy button
        /// </summary>
        DisableBuyButton = 1,
        /// <summary>
        /// Unpublish
        /// </summary>
        Unpublish = 2,
    }
15 years ago
I am getting the same error when trying to create a new product - I am using the latest version with a clean install - and I dont have a clue what you mean by the above post. Can you give us a solution or a fix ?

Neil
15 years ago
Bug. Exceute the following statement over your database:

ALTER PROCEDURE [dbo].[Nop_ProductVariantInsert]
(
  @ProductVariantID int = NULL output,
  @ProductId int,
  @Name nvarchar(400),
  @SKU nvarchar (400),
  @Description nvarchar(4000),
  @AdminComment nvarchar(4000),
  @ManufacturerPartNumber nvarchar(100),
  @IsDownload bit,
  @DownloadID int,
  @IsShipEnabled bit,
  @IsFreeShipping bit,
  @IsTaxExempt bit,
  @TaxCategoryID int,
  @StockQuantity int,
  @MinStockQuantity int,
  @LowStockActivityID int,
  @WarehouseId int,
  @DisableBuyButton int,
  @RequiresTextOption bit,
  @TextOptionPrompt nvarchar(400),
  @Price money,
  @OldPrice money,
  @Weight float,
  @Length decimal(18, 4),
  @Width decimal(18, 4),
  @Height decimal(18, 4),
  @PictureID int,
  @Published bit,
  @Deleted bit,
  @DisplayOrder int,
  @CreatedOn datetime,
  @UpdatedOn datetime
)
AS
BEGIN
  INSERT
  INTO [Nop_ProductVariant]
  (
    ProductId,
    [Name],
    SKU,
    [Description],
    AdminComment,
    ManufacturerPartNumber,
    IsDownload,
    DownloadID,
    IsShipEnabled,
    IsFreeShipping,
    IsTaxExempt,
    TaxCategoryID,
    StockQuantity,
    MinStockQuantity,
    LowStockActivityID,
    WarehouseId,
    DisableBuyButton,
    RequiresTextOption,
    TextOptionPrompt,
    Price,
    OldPrice,
    Weight,
    [Length],
    Width,
    Height,
    PictureID,
    Published,
    Deleted,
    DisplayOrder,
    CreatedOn,
    UpdatedOn
  )
  VALUES
  (
    @ProductId,
    @Name,
    @SKU,
    @Description,
    @AdminComment,
    @ManufacturerPartNumber,
    @IsDownload,
    @DownloadID,
    @IsShipEnabled,
    @IsFreeShipping,
    @IsTaxExempt,
    @TaxCategoryID,
    @StockQuantity,
    @MinStockQuantity,
    @LowStockActivityID,
    @WarehouseId,
    @DisableBuyButton,
    @RequiresTextOption,
    @TextOptionPrompt,
    @Price,
    @OldPrice,
    @Weight,
    @Length,
    @Width,
    @Height,
    @PictureID,
    @Published,
    @Deleted,
    @DisplayOrder,
    @CreatedOn,
    @UpdatedOn
  )

  set @ProductVariantID=@@identity
END
15 years ago
Thank you for the code :). Now it is fine.
15 years ago
Hi Support,
I am truly impressed by the speed of response. Please keep up the fantastic work you guys are doing. The problem and all regressions related to this are now fixed.
Thank you!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.