Shihe Zhang
Shihe Zhang

Reputation: 2771

mysqldump lost referential action subclause of foreign key constraints

After dump with

mysqldump --no-data -h localhost -u root -p my_db | sed 's/ AUTO_INCREMENT=[0-9]*//g' > $DEST_FILE

part of the foreign key constraints lost like this:

ORIGIN:

  CONSTRAINT `fk_owner_id_app_group` FOREIGN KEY (`owner_id`) REFERENCES `app_user` (`app_user_id`) ON DELETE RESTRICT ON UPDATE RESTRICT

AFTER:

CONSTRAINT `fk_owner_id_app_group` FOREIGN KEY (`owner_id`) REFERENCES `app_user` (`app_user_id`)

The ON DELETE RESTRICT ON UPDATE RESTRICT part lost.
No error or warning issued during exporting.
Checked mysqldump manual, didn't find any related options. https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html Have anyone experienced this? Is this a mysqldump bug?

The environment here is.
mysqldump Ver 10.13 Distrib 5.7.25, for Linux (x86_64)
mysql Ver 14.14 Distrib 5.7.25, for Linux (x86_64) using EditLine wrapper

Upvotes: 0

Views: 60

Answers (1)

fancyPants
fancyPants

Reputation: 51888

Simple answer is, that it's omitted because it's the default anyway.

From the manual:

  • RESTRICT: Rejects the delete or update operation for the parent table. Specifying RESTRICT (or NO ACTION) is the same as omitting the ON DELETE or ON UPDATE clause.

For an ON DELETE or ON UPDATE that is not specified, the default action is always RESTRICT.

Upvotes: 1

Related Questions