Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
RajRoR opened this issue Oct 1, 2024 · 2 comments

Comments

@RajRoR
Copy link

RajRoR commented Oct 1, 2024

> 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

@mikeheft
Copy link

I have also run into this recently out of the blue AFAICT. No one else on my team is running into this issue. I've deleted all of my bundled gems and re-bundled but that did nothing. I don't want to have to modify the code, since it's only me experiencing this, but I would think the cascade would be standard in the truncation?

@RajRoR
Copy link
Author

RajRoR commented Dec 19, 2024

@mikeheft - Is your gem version is different from your teams'? Try version 2.1. It should fix this problem. I hope that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants