I have migrated a Magento 2 site to a new server and getting the below error when placing order

We cant place the order : SQLSTATE[HY000]: General error: 1449 The user specified as a definer your_db_user@% does not exist, query was: UPDATE cataloginventory_stock_item SET qty = CASE product_id WHEN 65464 THEN qty-1 ELSE qty END WHERE (product_id IN (65464)) AND (website_id = 0)"}],"data_id":1563289789}}


After migrating the site I got the above error on placing the order. The user that was trying to access the DB is an old server DB user which didn't exist in the new server.

I searched for the user in DB and Code to make sure something wasn't hard coded and nothing was hardcoded.

Finally, after googling a bit I found a solution :

Problem: Magento creates a view which has a definer which has the name of the old user.

Solution : 1) Go to PHPMyAdmin 2) Select the table giving the error 3) Click on Triggers 4) Edit the trigger and Change the OLD user to the new DB user

And it's solved.

Thank you.

| improve this answer | |

As far as I'm aware they've created only one view table

If you use mysqldump you end up with this

CREATE ALGORITHM=UNDEFINED DEFINER=`dbusername`@`localhost` SQL SECURITY INVOKER VIEW `inventory_stock_1`  AS  select distinct `legacy_stock_status`.`product_id` AS `product_id`,`legacy_stock_status`.`website_id` AS `website_id`,`legacy_stock_status`.`stock_id` AS `stock_id`,`legacy_stock_status`.`qty` AS `quantity`,`legacy_stock_status`.`stock_status` AS `is_salable`,`product`.`sku` AS `sku` from (`dbname`.`cataloginventory_stock_status` `legacy_stock_status` join `dbname`.`catalog_product_entity` `product` on((`legacy_stock_status`.`product_id` = `product`.`entity_id`)));

Which will either fail to import or create issues. Instead you should swap it in dump with this

VIEW `inventory_stock_1` AS select
    distinct `legacy_stock_status`.`product_id` AS `product_id`,
    `legacy_stock_status`.`website_id` AS `website_id`,
    `legacy_stock_status`.`stock_id` AS `stock_id`,
    `legacy_stock_status`.`qty` AS `quantity`,
    `legacy_stock_status`.`stock_status` AS `is_salable`,
    `product`.`sku` AS `sku`
    ( `cataloginventory_stock_status` `legacy_stock_status`
join `catalog_product_entity` `product` on
        (( `legacy_stock_status`.`product_id` = `product`.`entity_id` )));
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.