J.D*_*.D. 8 postgresql node.js knex.js
我正在使用knex在postgres数据库中创建一个简单的表:
function up(knex, Promise) {
return knex.schema.createTableIfNotExists('communities', (table) => {
table.increments('id').primary().unsigned();
table.string('name', 255).notNullable();
table.string('slug', 100).notNullable();
table.timestamp('createdAt').defaultTo( knex.fn.now() );
table.timestamp('updatedAt');
});
Run Code Online (Sandbox Code Playgroud)
};
function down(knex, Promise) {
return knex.schema.dropTableIfExists(tableName);
};
module.exports = {
tableName,
up,
down
}
Run Code Online (Sandbox Code Playgroud)
我的问题是table.increments('id').primary()创建一个默认值具有的主键,nextval('communities_id_seq'::regclass)我不能在没有id的情况下进行插入(即使在原始sql中).
有没有人知道如何默认增加id?
| 归档时间: |
|
| 查看次数: |
7845 次 |
| 最近记录: |