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

北慕城南 提交于 2020-07-20 17:12:07

问题


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

The Command which occur the pervious message

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

Swagger Error 500

{"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

Also here's what I got in admin dashboard

Admin Panel error

[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


回答1:


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.



来源:https://stackoverflow.com/questions/50690185/magento-2-sqlstatehy000-general-error-1823-failed-to-add-the-foreign-key-con

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!