小编Cod*_*234的帖子

如何使用 Knex.js 添加复合主键?

我有2张桌子。1 调用带有事件 ID 的事件和另一个称为票证的表,我希望它具有事件 ID 和票证 ID 的主键。我也在使用 PostgreSQL 数据库。目前,我将它作为外键,但希望将它作为带有票证 ID 的票证表中的主键。

knex.schema.createTable('events', function (table) {
    table.increments('id');
    table.string('eventName');
});

knex.schema.createTable('tickets', function (table) {
    table.increments('id');
    table.string('ticketName');

    table.foreign('tickets').references('events_id').inTable('events');
});
Run Code Online (Sandbox Code Playgroud)

postgresql composite-primary-key knex.js

11
推荐指数
2
解决办法
9504
查看次数