Comments (7)
The #58 change also breaks if you use active storage.
ActiveRecord::StatementInvalid:
PG::FeatureNotSupported: ERROR: cannot truncate a table referenced in a foreign key constraint
DETAIL: Table "active_storage_variant_records" references "active_storage_blobs".
HINT: Truncate table "active_storage_variant_records" at the same time, or use TRUNCATE ... CASCADE.
maybe we could add some option to choose between CASCADE
and RESTRICT
.
from database_cleaner-active_record.
As of today, 1.99.0 is still the newest version working for us.
from database_cleaner-active_record.
Downgrading to gem 'database_cleaner-active_record', '2.0.0'
fixes it.
I got weider version of error (for 2.0.1)
ActiveRecord::StatementInvalid:
PG::FeatureNotSupported: ERROR: cannot truncate a table referenced in a foreign key constraint
DETAIL: Table "product_variants" references "product_variants".
HINT: Truncate table "product_variants" at the same time, or use TRUNCATE ... CASCADE.
note the same table references.
But structure.sql
do not mention such reference
ALTER TABLE ONLY catalog.product_variants
ADD CONSTRAINT variants_product_id_fk FOREIGN KEY (product_id) REFERENCES catalog.products(id) ON DELETE CASCADE;
ALTER TABLE ONLY stats.product_variants
ADD CONSTRAINT fk_rails_ba48c4f29e FOREIGN KEY (product_variant_id) REFERENCES catalog.product_variants(id);
from database_cleaner-active_record.
Is there any plans on mitigating this issue?
from database_cleaner-active_record.
@GoktugOzturk @foton @marcocarvalho @tanelsuurhans I was the original contributor who introduced using RESTRICT
because in organization I was working at the time using CASCADE
was silently dropping tables that we wanted to not drop. It cause us a lot of time to debug what is happening and this change was intended to make it more visible if you don't declare upfront all related tables you want to retain in the database.
I know that the issue was introduced almost 2 years ago and I'm sorry I haven't noticed it since then, which isn't the best example of how ownership should work in OSS 🙈
Could you give me more details on the issue? Are the tables that cause it to blow up created dynamically so you don't know what are their names at the time of declaring which tables to truncate?
from database_cleaner-active_record.
@bsuchodolski, in our case, it is marked as part of the tables to be truncated. There are other tables containing configurations that are not truncated. However, the tables raising the error are marked for truncation but raise the error because of foreign key references. Would it make sense to set RESTRICT
and CASCADE
via configuration rather than hard-coding it?
from database_cleaner-active_record.
When doing a big Ruby+Rails upgrade on a Rails 5 app, I've encountered this same issue when needing to bump DatabaseCleaner and other gems for compatibility.
For now I forked the repository and reverted this change: #58
I think this could be an option to choose from as variants of the truncation strategy.
from database_cleaner-active_record.
Related Issues (20)
- Transaction strategy configured with symbol(connection name) does not work HOT 1
- CI is not being executed against Rails 7.1 stable (and probably 7.1 compatibility is broken on main)
- Cleaning does not occur on subsequent specs when there are two databases and shared examples HOT 1
- Upgrade from 2.1.0 to 2.2.0 breaks Rails initialization
- Default CASCADE option when truncating with postgres is not intuitive HOT 4
- Where's the changelog? HOT 3
- Delete cascade HOT 1
- README.md -> invalid ruby syntax
- Cleaning fails with PG::UndefinedColumn: ERROR: column "increment_by" does not exist HOT 2
- Always exclude `pg_*` tables in PostgreSQL truncation
- Broken with Rails 7.1 HOT 2
- edge rails (future 7.1) no longer has ActiveRecord::SchemaMigration.table_name HOT 4
- v2.0.1 is throwing deprecation warning for using #tables instead of #data_sources HOT 3
- Stale connection in `DatabaseCleaner::ActiveRecord::Truncation#connection` HOT 1
- truncation and deletion doesn't call after_commit
- Issue with the upcoming Factory Bot Rails due to lacking of lazy load hooks HOT 4
- Unable to load application: LoadError: cannot load such file -- database_cleaner/active_record
- [FIX] Make more meaningful methods name
- Accidental replacement of main DB model connections in multi-database env
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from database_cleaner-active_record.