Skip to content

Cannot truncate a table referenced in a foreign key constraint (ActiveRecord::StatementInvalid) #717

Description

@RajRoR
> DatabaseCleaner.clean_with(:truncation, pre_count: true)

(reverb):1:in `<main>': PG::FeatureNotSupported: ERROR:  cannot truncate a table referenced in a foreign key constraint (ActiveRecord::StatementInvalid)
DETAIL:  Table "table1" references "table2".
HINT:  Truncate table "table1" at the same time, or use TRUNCATE ... CASCADE.

/root/project/vendor/bundle/ruby/3.1.0/gems/activerecord-7.2.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:56:in `exec': ERROR:  cannot truncate a table referenced in a foreign key constraint (PG::FeatureNotSupported)

DETAIL:  Table "table1" references "table2".
HINT:  Truncate table "table1" at the same time, or use TRUNCATE ... CASCADE.

Rails 7.2.1
ActiveRecord 7.2.1
DatabaseCleaner 2.0.2
DatabaseCleaner-ActiveRecord 2.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions