我试图在使用sails.js框架时添加一个postgresql数据库。
但是,我试图在我的数据库中保存一些模型值,但是,我得到了以下错误:error: null value in column "id" violates not-null constraint。在postgresql数据库中是否有一种方法来存储由水系自动创建的id?
/models/user.js
module.exports = {
connection: 'postgresqlServer',
schema: true,
attributes: {
id: {
type: 'integer',
primaryKey: true
},
name: {
type: 'string',
required: true
}
}
};/config/connection.js
module.exports.connections = {
postgresqlServer: {
adapter: 'sails-postgresql',
host: 'localhost',
user: 'root',
password: '',
database: 'myprojectdb',
socketPath: '/Library/Application Support/Postgres/var-9.5',
schema: true
}
};config/models.js
module.exports.models = {
connection: 'sails-postgresql',
migrate: 'alter'
};发布于 2016-02-06 19:24:05
您应该为您的autoIncrement: true属性设置id。
顺便说一句:水线会自动将id添加到每个型号中。如果需要,可以使用autoPK: false禁用它。
https://stackoverflow.com/questions/35242108
复制相似问题