如果我有一个模型,定义如下:
const Person = DB.define('PERSON', {
id: {
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4,
primaryKey: true
},
firstName: {
type: Sequelize.STRING,
field: 'first_name'
}
});
然后,在创建过程中,以下操作失败:
await Person.create({
firstName: 'John'
});
与
Error: Data truncated for column 'first_name' at row 1
在上述
firstName
调用中将first_name
替换为create
可解决此问题。
问题:有两种方法都可以做到吗?在数据库中强调并骆驼在JavaScript创建调用中被强调了吗?
实例(上面的DB
引用)的定义如下:
const DB = new Sequelize(DB_NAME, DB_USER, DB_PASS, {
host: DB_HOST,
port: DB_PORT,
dialect: 'mysql',
operatorsAliases: false,
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},
define: {
underscored: true,
freezeTableName: true
}
});