-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Closed
Labels
type: bugDEPRECATED: replace with the "bug" issue typeDEPRECATED: replace with the "bug" issue type
Description
What are you doing?
I am trying to bulk create records and run individualHooks. As per the below sscce. There seems to be an issue with camelCased fields that have no default value.
const Sequelize = require('./index');
const sequelize = require('./test/support').createSequelizeInstance();
const DataTypes = Sequelize.DataTypes;
const company = sequelize.define('company', {
id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
field: 'id'
},
createdBy: {
type: DataTypes.TEXT,
allowNull: false,
field: 'created_by'
},
name: {
type: DataTypes.TEXT,
allowNull: false,
field: 'name'
},
companyRegNumber: {
type: DataTypes.TEXT,
allowNull: false,
field: 'company_reg_number'
}
}, {
tableName: 'company'
});
sequelize.sync().then(() => {
company.bulkCreate([
{
name: 'test1',
createdBy: 'Dave',
companyRegNumber: '1234'
},
{
name: 'test2',
createdBy: 'Bob',
companyRegNumber: '5678'
}
], {
individualHooks: true
}).then(entities => {
console.log(entities.map(e => e.dataValues));
process.exit();
});
}).catch(e => {
console.log(e);
process.exit();
});What do you expect to happen?
I expect the created records to be outputted to the console.
What is actually happening?
SequelizeDatabaseError: null value in column "created_by" violates not-null constraint
Debugging
I have had a look at this, and it appears to come from mapValueFieldNames.
dataValues are passed in as:
{ id: null,
created_by: 'Dave',
name: 'test1',
company_reg_number: '1234',
createdAt: 2018-05-23T18:28:10.101Z,
updatedAt: 2018-05-23T18:28:10.101Z }
{ id: null,
created_by: 'Bob',
name: 'test2',
company_reg_number: '5678',
createdAt: 2018-05-23T18:28:10.101Z,
updatedAt: 2018-05-23T18:28:10.101Z }And values is returned as:
{ id: null,
name: 'test1',
createdAt: 2018-05-23T18:28:10.101Z,
updatedAt: 2018-05-23T18:28:10.105Z }
{ id: null,
name: 'test2',
createdAt: 2018-05-23T18:28:10.101Z,
updatedAt: 2018-05-23T18:28:10.105Z }Dialect: postgres
Dialect version: 7.4.3
Database version: 10
Sequelize version: 5.0.0-beta.6
Tested with latest release: Yes - 5.0.0-beta.6
cettoana
Metadata
Metadata
Assignees
Labels
type: bugDEPRECATED: replace with the "bug" issue typeDEPRECATED: replace with the "bug" issue type