Foreign Key Constraints on seeding

Posted 4 years ago by WillyCornelissen

when I am running a db:seed I disabled foreign key constraints on DatabaseSeeder.php:

    Model::unguard();
    DB::statement('SET FOREIGN_KEY_CHECKS=0;');
    $this->call('UsersTableSeeder');
    ........
    DB::statement('SET FOREIGN_KEY_CHECKS=1;');

It works fine with MySQL, but if I change the database configuration to sqlite I got the following error:

SQLSTATE[HY000]: General error: 1 near "SET": syntax error (SQL: SET FOREIGN_KEY_CHECKS=0;

If I change the database configuration to postgres I got the following error:

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

Any idea of what's going on?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.