How to fix error in mysql: ERROR 1452 (23000) CONSTRAINT in magento 2 ?

use this command to find the rows that need to be deleted:

select * from orders where cid not in (select distinct id from customers);

Also you can check in sql file who have rights to database