Using mysql 5.7 and node 12.
The table schema is like this
name varchar(255) not null primary key,
createdAt timestamp default CURRENT_TIMESTAMP not null,
Now if i do
mysql> insert into myTable (name, createdAt) values ('name1', 'DEFAULT');
it works, but if i do
mysql> insert into myTable (name, createdAt) values ('name1', null);
it will say "cannot be null".
So i try to set the value to be DEFAULT if needed, go to my node code,
const addEntry (inputObj) => {
const sqlCmd = `insert into myTable (name, createdAt)
values ( ? ? )`;
const param = ['name1', inputObj.createdAt || 'DEFAULT'];
mysql.query(sqlCmd, param);
}
when i test it, don't define the createdAt property, inputObj = { 'name': 'name1' };
it errors
Error: ER_TRUNCATED_WRONG_VALUE: Incorrect datetime value: 'DEFAULT' for column 'createdAt' at row 1
How to fix this please ?