database_cleaner-sequel icon indicating copy to clipboard operation
database_cleaner-sequel copied to clipboard

Truncation via Sequel fails on Mysql when foreign key constraints are present

Open contentfree opened this issue 11 years ago • 1 comments

ActiveRecord has disable_referential_integrity; unfortunately Sequel doesn't. Documentation for working around this would be very useful. (Maybe doing a raw SQL statement to disable foreign keys before doing the clean?)

contentfree avatar Aug 14 '14 07:08 contentfree

@contentfree A bit late, but I ran into the same issue. I am using MySQL and solved it like this:

DB.run('SET FOREIGN_KEY_CHECKS=0;')
DatabaseCleaner.clean_with(:truncation)
DB.run('SET FOREIGN_KEY_CHECKS=1;')

baschtl avatar Feb 24 '17 10:02 baschtl