Answer the question
In order to leave comments, you need to log in
Why doesn't autoincrement generate an id?
Good morning. Please tell me why the specified parameter does not work? I took the example from the documentation, substituted my fields.
const sequelize = new Sequelize('test', 'root', '', {
host: 'localhost',
dialect: 'mysql'
});
sequelize
.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
})
.catch(err => {
console.error('Unable to connect to the database:', err);
});
const User = sequelize.define('users', {
// attributes
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true //Должен генерировать id
// defaultValue: 123 - пределение id в ручную,но в документации этого не было,я это выгуглил
},
email: {
type: Sequelize.STRING,
allowNull: false
},
password: {
type: Sequelize.STRING
// allowNull defaults to true
}
}, {
// options
});
User.create({ email: "Jane", password: "Doe" }).then(jane => {
console.log("Jane's auto-generated ID:", jane.id);
});
Answer the question
In order to leave comments, you need to log in
There was a conflict between v5 / v4 versions, I replaced the config with the config from the v4 docks and it all worked
https://stackoverflow.com/questions/15737949/how-d... - don't create an id column and that's it. Sequelize will do it itself
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question