steven-ferguson / knex-cleaner

Database cleaner for Knex.js
Other
79 stars 38 forks source link

The order of cleaning violate constraints sometimes. #25

Open lucasm0ta opened 6 years ago

lucasm0ta commented 6 years ago

Sometimes, it tries to clean a table before the one it references causing constraints violation.

ER_ROW_IS_REFERENCED_2: Cannot delete or update a parent row: a foreign key constraint fails (`Company`.`data_datalogger`, CONSTRAINT `fk17` FOREIGN KEY (`id_brand_datalogger`) REFERENCES `brand_datalogger` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION)

Is there a way to manage the order of cleaning?

nickygb commented 3 years ago

If you use mode: truncate it disable foreign key checks.

https://github.com/steven-ferguson/knex-cleaner/blob/0a27ed38138f1eb1c0c6453d5a4035aba064d916/lib/knex_cleaner.js#L40

joelanman commented 4 months ago

using mode: truncate worked for me, would be helpful to add to the documentation