Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

canfone's avatar

PostgreSQL truncate in DB:Seed

Hi,

I'm working on a project right now using PostgreSQL. in my seeder, I truncated my table including those who have a foreign key constraint. I tried to use this

DB::statement('SET FOREIGN_KEY_CHECKS=0;');

but it triggers an error.

[Illuminate\Database\QueryException]
  SQLSTATE[42704]: Undefined object: 7 ERROR:  unrecognized configuration parameter "foreign_key_checks" (SQL: SET FOREIGN
  _KEY_CHECKS=0;)

What should be the equivalent FOREIGN_KEY_CHECK in PostgreSQL?

Thanks,

0 likes
2 replies
canfone's avatar
canfone
OP
Best Answer
Level 1

Hi @Mittensoff , Thanks for your response. I figured out how I truncate my table in PostgreSQL by using this code snippet.

DB::statement("TRUNCATE TABLE {$table} RESTART IDENTITY CASCADE");

Please or to participate in this conversation.