您可以在数据库中使用此命令 `ALTER TABLE your_table ADD COLUMN key_column BIGSERIAL PRIMARY KEY;
在 Sails 模型中,您可以使用如下内容:
module.exports = {
connection: yourConnection,
tableName: yourTableName,
attributes: {
id: {
type: 'integer',
autoIncrement: true,
primaryKey: true
},
email: {
type: 'email',
required: true,
unique: true
}
}
注意:您需要在之前设置您的数据库连接配置config/connections.js
somePostgresqlServer: {
adapter: 'sails-postgresql',
host: 'YOUR_POSTGRES_SERVER_HOSTNAME_OR_IP_ADDRESS',
user: 'YOUR_POSTGRES_USER',
password: 'YOUR_POSTGRES_PASSWORD',
database: 'YOUR_POSTGRES_DB'
}
并npm install sails-postgresql
在您的项目文件夹中运行