Skip to content

Cannot add product in admin if single store mode website id != 1 #35009

@kyegil

Description

@kyegil

I'm not able to add any products from admin. My Magento is in single store mode with website id = 2.
Saving a new product fails with Integrity constraint violation.
Editing and saving an existing product works fine. I am also able to create new products using the import feature.
The issue was reproduced on a clean Magento instance.

Preconditions (*)

  1. Magento Open Source 2.4.3-p1
  2. php 7.4
  3. MariaDB 10.4

Steps to reproduce (*)

  1. Install a clean version of Magento version 2.4.3-p1
  2. Add a new website, store and store view, and make this the default
  • In Stores -> All Stores:

    • Create new website (new_website)
    • Create new store (new_store) under new_website
    • Create new store view (new_store_view) under new_store
  • Open new_website again, and set this as default. Save.

  1. Delete the preinstalled website (base)

  2. Verify your website db entries. The default website should be 2:

    SELECT * FROM store_website;
    +------------+-------------+-------------+------------+------------------+------------+
    | website_id | code        | name        | sort_order | default_group_id | is_default |
    +------------+-------------+-------------+------------+------------------+------------+
    |          0 | admin       | Admin       |          0 |                0 |          0 |
    |          2 | new_website | New Website |          0 |                2 |          1 |
    +------------+-------------+-------------+------------+------------------+------------+
    
    
  3. In Stores -> Configuration -> General -> SIngle-Store Mode

  • Enable Single-store Mode. Save.
  1. Verify your Single-store configuration:

    bin/magento config:show general/single_store_mode/enabled
    

    Should return 1

  2. In Catalog -> Products

  • Add Product
  • Populate name, sku and price. Save.

Expected result (*)

  1. The product should save successfully

Actual result (*)

  1. The save action fails, with the following message:
`SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`denuhabsxr`.`catalog_product_website`, CONSTRAINT `CATALOG_PRODUCT_WEBSITE_WEBSITE_ID_STORE_WEBSITE_WEBSITE_ID` FOREIGN KEY (`website_id`) REFERENCES `store_website` (`website_id`) ON DELETE ), query was: INSERT INTO `catalog_product_website` (`product_id`,`website_id`) VALUES (?, ?)`

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: ProductComponent: CatalogFixed in 2.4.xThe issue has been fixed in 2.4-develop branchIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: doneReported on 2.4.3-p1Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branch

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions