I get this error "RequestError: Cannot insert an explicit value into a timestamp column. Use INSERT with a column list to exclude the timestamp column, or insert a DEFAULT into the timestamp column.".
My database schema looks something like this ,
class Owner extends Model {}
Owner.init({
name: Sequelize.STRING,
}, { sequelize,timestamps: false });
class Hotel extends Model {}
Hotel.init({
name: Sequelize.STRING,
}, { sequelize,timestamps: false });
class Users extends Model {}
Users.init({
name: Sequelize.STRING
}, { sequelize,timestamps: false });
class User_Hotel extends Model {}
User_Hotel.init({
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
}
}, { sequelize,timestamps: false });
class Hotel_Owner extends Model {}
Hotel_Owner.init({
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
}
}, { sequelize,timestamps: false });
Owner.belongsToMany(Hotel, { through: { model: Hotel_Owner, unique: false } });
Hotel.belongsToMany(Owner, { through: { model: Hotel_Owner, unique: false } });
Hotel.belongsToMany(Users, { through: { model: User_Hotel, unique: false } });
Users.belongsToMany(Hotel, { through: { model: User_Hotel, unique: false } });
Now, I have to insert data in my tables, which I do something like this.
hotel = Hotel.create({name:"WestIn"});
[owner,created] = Owner.findOrCreate({where:{name:"John Doe"}});
Hotel_Owner.create({OwnerId: owner.id, HotelId: hotel.id });
user = Users.create({name:"Common man"});
User_Hotel.create({ HotelId: hotel.id , UsersId:user.id});
I am not sure , why I am getting this error.
awaiting just about everything, e.g.:hotel = await Hotel.create({name:"WestIn"});HoteldandUserId, which is why I was getting that Error. The error message is not appropriate. It is no where related to timestamps, rather it signifies that the column I am trying to insert doesn't exist in the table.