Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento 2 SQLSTATE[HY000]: General error: 1823 Failed to add the foreign key constraint

Hello guys I was getting errors with my Magento 2 Store.. Such as Failed API Requests, Swagger gives 500, Stylesheets and JS files won't load etc..

Finally I found that the best solution to create a fresh Magento installation with fresh theme files and just copy pub/media from files and go with maintenance mode to drop all tables prefixed with customers_ , catalog_ , sales_ and eav_

This step made my new store works very good but I got new kind of errors .. I can't run setup:upgrade it shows a message with:

[PDOException] SQLSTATE[HY000]: General error: 1823 Failed to add the foreign key constraint 'porosec_pororom/CAT_CTGR_PRD_CTGR_ID_CAT_CTGR_ENTT_ENTT_ID' to system tables

Error when I run php -f bin/magento setup:db-schema:upgrade

enter image description here

The Command which occur the pervious message

enter image description here

also when I run composer update it updates many of dependencies but it require to run setup:upgrade.

Swagger Error 500

enter image description here

{"0":"Please upgrade your database: Run \"bin/magento setup:upgrade\" from the Magento root directory.\nThe following modules are outdated:\nKlarna_Core data: current version - 4.1.5, required version - 4.2.3\nKlarna_Ordermanagement data: current version - 4.1.2, required version - 4.1.3","1":"#0 /home/porosec/public_html/test/vendor/magento/framework/Interception/Interceptor.php(121): Magento\Framework\Module\Plugin\DbStatusValidator->beforeDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Magento\Framework\App\Request\Http))\n#1 /home/porosec/public_html/test/vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php(73): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))\n#2 /home/porosec/public_html/test/vendor/magento/framework/Interception/Interceptor.php(135): Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))\n#3 /home/porosec/public_html/test/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))\n#4 /home/porosec/public_html/test/generated/code/Magento/Framework/App/FrontController/Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)\n#5 /home/porosec/public_html/test/vendor/magento/framework/App/Http.php(135): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))\n#6 /home/porosec/public_html/test/generated/code/Magento/Framework/App/Http/Interceptor.php(24): Magento\Framework\App\Http->launch()\n#7 /home/porosec/public_html/test/vendor/magento/framework/App/Bootstrap.php(256): Magento\Framework\App\Http\Interceptor->launch()\n#8 /home/porosec/public_html/test/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))\n#9 {main}","url":"/test/swagger","script_name":"/test/index.php"}

Swagger Error log

enter image description here

Also here's what I got in admin dashboard

Admin Panel error

enter image description here

[2018-06-04 23:18:09] main.CRITICAL: Report ID: webapi-5b15c8b17792e; Message: Class "array" does not exist. Please note that namespace must be specified. {"exception":"[object] (Exception(code: 0): Report ID: webapi-5b15c8b17792e; Message: Class \"array\" does not exist. Please note that namespace must be specified. at /home/porosec/public_html/test/vendor/magento/framework/Webapi/ErrorProcessor.php:205, LogicException(code: 0): Class \"array\" does not exist. Please note that namespace must be specified. at /home/porosec/public_html/test/vendor/magento/framework/Reflection/TypeProcessor.php:139)"} []

Admin Panel error log

enter image description here

like image 844
Kareem Arafa Avatar asked Nov 07 '22 06:11

Kareem Arafa


1 Answers

if you have taken the backup of same table and if foreign key constraint is same as bkp table and current table mysql will throw exception, so change the constraint name or delete the existing constraint.

constraint name should not be same.

like image 80
kishan singh Avatar answered Nov 14 '22 20:11

kishan singh