tôi đã không tìm thấy một xây dựng theo cách để làm điều đó, vì vậy tôi chỉ cần thả vào chế độ thô:
knex.raw('TRUNCATE TABLE users, products CASCADE')
Bạn cũng có thể thiết lập này xảy ra tự động trong cuộc di cư của bạn:
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');
});
};