php – Laravel 8: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails

I want to apply OneToMany Relationship between users and roles table and I have already some data in these two tables.

So in order to make this relationship, I made this Migration for adding role_id to users table:

public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->unsignedBigInteger('role_id')->nullable()->unsigned();
            $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
        });
    }

But when I want to run this Migration, I get this error:

SQLSTATE(42S21): Column already exists: 1060 Duplicate column name
‘role_id’ (SQL: alter table users add role_id bigint unsigned
null)

So what is going wrong here ? How can I fix this issue ?

Here is also the Migration of roles table:

public function up()
    {
        Schema::create('roles', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('slug');
            $table->timestamps();
        });
    }

M1 to M2 migration – SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry

I am in the process of migrating a site from M1 to M2

I have run the following command successfully a few times:

bin/magento migrate:delta --auto /app/code/Vendor/Migration/etc/opensource-to-opensource/1.9.4.5/config.xml

The last time I ran it the following error was displayed:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1617
  3-1' for key 'CATALOGINVENTORY_STOCK_ITEM_PRODUCT_ID_STOCK_ID'

Any ideas?

8 – error SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry

I’m currently migrating my website to D8 and I’m having some issues updating my NEW nodes to match with my live D7 site.

I get a few of these for each content type. I think it’s from creating “test page” and the node ID is taken.

I get a few of these warnings:

 (error)  SQLSTATE(23000): Integrity constraint violation: 1062 Duplicate entry 'e0891884-4da7-45c9-a1b5-808c8f821cfa' for key 'node_field__uuid__value': UPDATE {node} SET vid=:db_update_placeholder_0, type=:db_update_placeholder_1, uuid=:db_update_placeholder_2, langcode=:db_update_placeholder_3
WHERE nid = :db_condition_placeholder_0; Array
(
 (:db_update_placeholder_0) => 61287
 (:db_update_placeholder_1) => festival
 (:db_update_placeholder_2) => e0891884-4da7-45c9-a1b5-808c8f821cfa
 (:db_update_placeholder_3) => und
 (:db_condition_placeholder_0) => 3943
)

I tried drush migrate-import upgrade_d7_node_festival --update , but that didn’t work. Is there a way to overwrite my test nodes when migrating? Do I have to go and delete all the table nodes in my DB then rerun the migration?

Thank!

product images – Data migration issue : SQLSTATE[23000]: Integrity constraint violation from maento 1.9 to magento 2.4.1

I am migrating the data from Magento 1 to magento 2.4.1 by running the following command

php bin/magento migrate:data –reset
vendor/magento/data-migration-tool/etc/opensource-to-opensource/1.9.0.1/config.xml

But it throws the following error and stopped migration

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘137-24’ for key ‘CAT_PRD_ENTT_MDA_GLR_VAL_TO_ENTT_VAL_ID_ENTT_ID’

please refer to the attachment

enter image description here

commerce – PDOException : SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘registration

Using: commerce+entity registration+commerce registration

During the checkout sequence, after completing the registration step, I get this fatal error:

PDOException : SQLSTATE(23000): Integrity constraint violation: 1062 Duplicate entry ‘registration-144-0-0-und’ for key ‘PRIMARY’: INSERT INTO {field_data_field_nom} (entity_type, entity_id, revision_id, bundle, delta, language, field_nom_value, field_nom_format) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7); Array ( (:db_insert_placeholder_0) => registration (:db_insert_placeholder_1) => 144 (:db_insert_placeholder_2) => 144 (:db_insert_placeholder_3) => formulaire_inscription (:db_insert_placeholder_4) => 0 (:db_insert_placeholder_5) => und (:db_insert_placeholder_6) => dfgh (:db_insert_placeholder_7) => ) in field_sql_storage_field_storage_write() (line 514 in /home//public_html///modules/field/modules/field_sql_storage/field_sql_storage.module).

I have tried to disable some rules that could be problematic, to disable multilanguage (entity registration have some problem whit multilang)… nothing.

What can be the cause of this error?

Thx

magento2.3.5 p1 – Magento 2.3.5-p1 – Data migration error – SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry

Migrate from magento 1.9.2.3 to 2.3.5.-p1 how to solve the following error,

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ’21-product-details’ for key ‘EAV_ATTRIBUTE_GROUP_ATTRIBUTE_SET_ID_ATTRIBUTE_GROUP_CODE’

Note: Settings migration successfully completed

magento2.3.4 – Magento 2.3 – Delta Migration SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry

Before a month successfully migrated settings and data, now I want to setup Delta migration for update orders and customer details if i run following command

php bin/magento migrate:delta
vendor/magento/data-migration-tool/etc/opensource-to-opensource/1.9.2.3/config.xml

I am getting the following error,

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry
‘4799 0-1’ for key
‘CATALOGINVENTORY_STOCK_ITEM_PRODUCT_ID_STOCK_ID’

How to solve the issue?

magento2.3 – After upgrading to 2.3.3 got SQLSTATE[23000]: Integrity Restriction Violation: 1022 Attempting to Run bin / magento setup: upgrade

I'm updating from 2.3.3 to 2.2.9 by following these steps (How do I update the Magento version from 2.2.X to 2.3.0?). However, at the step

& Php; bin / magento setup: upgrade & # 39;

I have the error message below

SQLSTATE (23000): Integrity Restriction Violation: 1022 Can not write;
Duplicate key in table # sql-1767_f1786 # query was: ALTER TABLE
catalog_product_entity_text CHANGE COLUMN value_id int (11) NOT
NULL AUTO_INCREMENT COMMENT "Value ID", ADD CONSTRAINT PRIMARY KEY
(value_id), ADD CONSTRAINT
CAT_PRD_ENTT_TEXT_ATTR_ID_EAV_ATTR_ATTR_ID UNKNOWN KEY
(attribute_id) REFERENCES eav_attribute (attribute_id) ON
DELETE CASCADE, ADD CONSTRAINT
CAT_PRD_ENTT_TEXT_ENTT_ID_CAT_PRD_ENTT_ENTT_ID UNKNOWN KEY
(entity_id) REFERENCES catalog_product_entity (entity_id) ON
DELETE CASCADE, ADD CONSTRAINT
CATALOG_PRODUCT_ENTITY_TEXT_STORE_ID_STORE_STORE_ID UNKNOWN KEY
(store_id) REFERENCES store (store_id) ADD TO DELETE CASCADE
FORCE
CATALOG_PRODUCT_ENTITY_TEXT_ENTITY_ID_ATTRIBUTE_ID_STORE_ID UNIQUE
KEY (entity_id.attribute_id.store_id), INDEX ADD
CATALOG_PRODUCT_ENTITY_TEXT_ATTRIBUTE_ID (attribute_id), INDEX ADD
CATALOG_PRODUCT_ENTITY_TEXT_STORE_ID (store_id)

magento 1.9 – PDOException: SQLSTATE[23000]: Violation of constraint: 1452 Can not add or update a child line

After creating a shopping cart rule for grouped products, I got them

catalog_product_attribute indexer

must be re-indexed.
When I tried reindexing from the console, I got:

Unknown error in product attribute process:
PDOException: SQLSTATE[23000]No information for the content. This can cause a crash that could violate the constraint: 1452 A constraint violation can not be raised: 1452 Can not modify or update a child row: A foreign key constraint fails ("wallshoplive") C) in / home / wpaper / public_html / lib / Zend / Db / statement / Pdo.php: 228
Stack trace:
# 0 /home/wpaper/public_html/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement-> Run (Array)
# 1 /home/wpaper/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo -> _ execute (Array)
# 2 /home/wpaper/public_html/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql -> _ Run (Array)
# 3 /home/wpaper/public_html/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement-> Run (Array)
# 4 /home/wpaper/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract-> query (& # 39; INSERT INTO ca ... & # 39 ;, Array)
# 5 /home/wpaper/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(504): Zend_Db_Adapter_Pdo_Abstract-> Query (& # 39; INSERT INTO Ca ... & # 39 ;, Array)
# 6 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Resource/Abstract.php(179): Varien_Db_Adapter_Pdo_Mysql-> query (& # 39; INSERT INTO `ca ... & # 39; )
# 7 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Resource/Helper/Mysql4.php(49): Mage_Index_Model_Resource_Abstract-> insertFromSelect (object (Varien_Db_Select) & # 39 ;, & # 39; catalog_product # wrong)
# 8 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Resource/Abstract.php(153): Mage_Index_Model_Resource_Helper_Mysql4-> insert (Object (Mana_Filters_Resource_Indexer_Source), Object (Varien_Db_Select),, catalog_product ... & # 39 ;, array, false)
# 9 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Resource/Abstract.php(113): Mage_Index_Model_Resource_Abstract-> insertFromTable (& # 39; catalog_product ... & # 39 ;, & # 39; catalog_product ... & # 39 ;, false)
# 10 /home/wpaper/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Eav/Abstract.php (54): Mage_Index_Model_Resource_Abstract-> syncData ()
# 11 /home/wpaper/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Eav.php(185): Mage_Catalog_Model_Resource_Product_Indexer_Eav_Abstract-> reindexAll ()
# 12 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Indexer/Abstract.php(143): Mage_Catalog_Model_Resource_Product_Indexer_Eav-> reindexAll ()
# 13 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Process.php(212): Mage_Index_Model_Indexer_Abstract-> reindexAll ()
# 14 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Process.php(260): Mage_Index_Model_Process-> reindexAll ()
# 15 /home/wpaper/public_html/shell/indexer.php(168): Mage_Index_Model_Process-> reindexEverything ()
# 16 /home/wpaper/public_html/shell/indexer.php(216): Mage_Shell_Compiler-> run ()
# 17 {main}

Next Zend_Db_Statement_Exception: SQLSTATE[23000]No information for the content. This can cause a crash that could violate the constraint: 1452 A constraint violation can not be raised: 1452 Can not modify or update a child row: A foreign key constraint fails ("wallshoplive") C) Query was: INSERT INTO_Catalog_product_index_eav` (`entity_id`,` attribut_id`, `store_id`,` value & # 39;). SELECT & # 39; catalog_product_index_eav_idx`.`entity_id`, `catalog_product_index_eav_idx`.`attribute_id`,` catalog_id & # 39; store_id`, `catalog_product_index_eav_idx`.`value` FROM` catalog_product_index_eav_idx` ON DUPLICATE KEY UPDATE` entity_id` = VALUES (`entity_id`),` attribute_id` = VALUES (`attribut_id`),` store_id`), `value` = VALUES (`value`) in /home/wpaper/public_html/lib/Zend/Db/Statement/Pdo.php:235
Stack trace:
# 0 /home/wpaper/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo -> _ execute (Array)
# 1 /home/wpaper/public_html/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql -> _ Run (Array)
# 2 /home/wpaper/public_html/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement-> Run (Array)
# 3 /home/wpaper/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract-> query (& # 39; INSERT INTO ca ... & # 39 ;, Array)
# 4 /home/wpaper/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(504): Zend_Db_Adapter_Pdo_Abstract-> Query (& # 39; INSERT INTO Ca ... & # 39 ;, Array)
# 5 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Resource/Abstract.php(179): Varien_Db_Adapter_Pdo_Mysql-> query (& # 39; INSERT INTO `ca ... & # 39; )
# 6 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Resource/Helper/Mysql4.php(49): Mage_Index_Model_Resource_Abstract-> insertFromSelect (object (Varien_Db_Select) & # 39 ;, & # 39; catalog_product # wrong)
# 7 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Resource/Abstract.php(153): Mage_Index_Model_Resource_Helper_Mysql4-> insert (Object (Mana_Filters_Resource_Indexer_Source), Object (Varien_Db_Select),, catalog_product ... & # 39 ;, array, false)
# 8 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Resource/Abstract.php(113): Mage_Index_Model_Resource_Abstract-> insertFromTable (& # 39; catalog_product ... & # 39 ;, & # 39; catalog_product ... & # 39 ;, false)
# 9 /home/wpaper/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Eav/Abstract.php (54): Mage_Index_Model_Resource_Abstract-> syncData ()
# 10 /home/wpaper/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Eav.php(185): Mage_Catalog_Model_Resource_Product_Indexer_Eav_Abstract-> reindexAll ()
# 11 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Indexer/Abstract.php(143): Mage_Catalog_Model_Resource_Product_Indexer_Eav-> reindexAll ()
# 12 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Process.php(212): Mage_Index_Model_Indexer_Abstract-> reindexAll ()
# 13 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Process.php(260): Mage_Index_Model_Process-> reindexAll ()
# 14 /home/wpaper/public_html/shell/indexer.php(168): Mage_Index_Model_Process-> reindexEverything ()
# 15 /home/wpaper/public_html/shell/indexer.php(216): Mage_Shell_Compiler-> run ()
# 16 {main}

I am using Magento 1.9.3.8

All other indexers work. Site works too.

Could anyone help me, please?