Skip to content

Model::truncate() cleares all foreign key records in postgres #29506

@ppshobi

Description

@ppshobi
  • Laravel Version: 5.8
  • PHP Version: 7.3
  • Database Driver & Version: Postgres 10

Description:

I believe this is something specific with Postgres

I am trying to truncate a table using Model::truncate() which of course truncates the table, and deletes all the foreign keyed records in the other tables. Even though ON DELETE CASCADE is not specified.

Tried to truncate the table within Schema::disableForeignKeyConstraints() & Schema::enableForeignKeyConstraints() statements. Still it clears all the records related via any foreign key. No exceptions or any warnings also.

Eg: truncating (temporarily) currency table will clear all the records in the products table 🥶

Is this an expected behaviour? it was not the case with MySQL. Mysql triggered errors when the FK constraints are active. And it didn't delete FK records

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions