Deactivate foreign key constraints for SQLServer truncateAllTables
MasterOdin opened this issue · comments
Matthew Peveler commented
truncateAllTables
fails on newer versions of SQLServer (2017+ at least) if there's foreign keys that exist between rows. Similar to MySQL, the foreign key constraints must be disabled when deleting the tables. Unfortunately, SQLServer does not support disabling it at a DB level, rather it's per table, so have to do a sequence of:
- Turn off foreign key constraints for all tables
- Truncate all tables
- Re-index tables
- Turn on foreign key constraints for all tables