I did not find a built-in way to do this, so I just go into raw mode:
knex.raw('TRUNCATE TABLE users, products CASCADE')
You can also set this automatically in your migrations:
exports.up = function(knex) { return knex.schema.createTable('users_products', (t) => { t.uuid('id').primary().defaultTo(knex.raw('uuid_generate_v4()')); t.uuid('user_id').notNullable().references('id').inTable('users').onDelete('CASCADE'); t.uuid('product_id').notNullable().references('id').inTable('products').onDelete('CASCADE'); }); };
source share