LoginSignup
0
0

More than 1 year has passed since last update.

Truncate時にCannot truncate a table referenced in a foreign key constraintとエラーが出た時の対処法

Posted at

解決策

以下のように外部キー制約を一時的に外してtruncateする

SET FOREIGN_KEY_CHECKS = 0; 
TRUNCATE table $table_name; 
SET FOREIGN_KEY_CHECKS = 1;

ちなみに、外部キー制約の状態は以下コマンドで確認可能

SELECT @@foreign_key_checks;
+----------------------+
| @@foreign_key_checks |
+----------------------+
|                    1 |
+----------------------+

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0