I'm using sequlize ORM for my Node.js project. Below code is one column in a table.
itemPrice: {
type: DataTypes.DECIMAL,
allowNull: false,
field: 'itemPrice'
},
It is generate the MYSQL DB column as decimal(10,0). It means it cannot save decimal points data. When I'm going to save 12.26, it is save 12. How to create column with saving 2 decimal points.
I tried below code also. It doesn't execute and occurred an error.
itemPrice: {
type: DataTypes.DECIMAL(10,2),
allowNull: false,
field: 'itemPrice'
},
Please show me a direction to do this...
type: DataTypes.DECIMAL(10,2),
should work. Once a table is created via sync
, it will not be altered even though you have changed your data model definition.
You can use {force: true}
in your sync
function. Remember that this will drop your table and recreate it.
sequelize.sync({ force: true })
.then(()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With