On MySql, in order to truncate a table or delete rows when it's normally impossible because of foreign keys (InnoDB only), we use this command:
SET FOREIGN_KEY_CHECKS=0;
On MariaDB, while this command is accepted, it does nothing.
The documentation says I have to run these commands instead:
On a per-table basis:
ALTER TABLE `...` DISABLE KEYS;
or, globally:
SET @@session.unique_checks = 0;
SET @@session.foreign_key_checks = 0;
So I tried to run this script:
SET FOREIGN_KEY_CHECKS=0;
SET @@session.unique_checks = 0;
SET @@session.foreign_key_checks = 0;
ALTER TABLE `country` DISABLE KEYS;
DELETE FROM `country` WHERE 1;
And that leads me to:
Cannot delete or update a parent row: a foreign key constraint fails (
database
.region
, CONSTRAINTFK_F62F176F92F3E70
FOREIGN KEY (country_id
) REFERENCEScountry
(id
))
Using TRUNCATE
has the same effect.
If you have any idea on what I may have missed, thank you by advance. Because the documentation and the existing questions weren't much of help here.
Best Answer
It should work with:
I tried the following:
So the problem is not with MariaDB, but with PhpMyAdmin. It has a checkbox on the pages where you can execute SQL, that overrides
SET FOREIGN_KEY_CHECKS=
. One must uncheck it if one wants to disable foreign key validation.