On renameColumn throw error if defaultValue CURRENT_TIMESTAMP
See original GitHub issueWhat are you doing?
I run migration with code:
await queryInterface.renameColumn(tableName, 'timestamp', 'updated_timestamp');
What do you expect to happen?
Migration successfully applied
What is actually happening?
Throw error:
{
Error: Invalid default value for 'updated_timestamp'
code: 'ER_INVALID_DEFAULT',
errno: 1067,
sqlState: '42000',
sqlMessage: 'Invalid default value for \'updated_timestamp\'',
sql: 'ALTER TABLE `billing_apple_callback` CHANGE `timestamp` `updated_timestamp` DATETIME NOT NULL DEFAULT \'CURRENT_TIMESTAMP\';'
}
SQL: ALTER TABLE `billing_apple_callback` CHANGE `timestamp` `updated_timestamp` DATETIME NOT NULL DEFAULT \'CURRENT_TIMESTAMP\';
Dialect: mysql Dialect version: musql2@1.5.1 Database version: 5.7.13 Sequelize version: 4.31.0 Tested with latest release: No
If change sql to ALTER TABLE `billing_apple_callback` CHANGE `timestamp` `updated_timestamp` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP;
all be fine. Error in \'
around CURRENT_TIMESTAMP
.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
mysql - Column name is not taking timestamp as default value
Should be something like this: ALTER TABLE nodestatics MODIFY COLUMN updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP;. ALTER TABLE nodestatics ...
Read more >Remove default value from NOT NULL column
The answer is to use the following (slightly odd) syntax: ALTER TABLE items ALTER ordering DROP DEFAULT;.
Read more >3630 Default value incompatible with type of column %VSTR.
3630 Default value incompatible with type of column %VSTR. Explanation: A value provided as a default for a non- nullable column is not ......
Read more >ALTER TABLE (Column) | Exasol DB Documentation
If the default value expression is not appropriate for the specified data type, ... statement does not throw an error message if the...
Read more >ALTER TABLE statement - Sybase Infocenter
To provide a default value on insert, but not update the column whenever the row is updated, use DEFAULT CURRENT TIMESTAMP instead of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think you have set
defaultValue
for this attribute toCURRENT_TIMESTAMP
, remove that and let Sequelize handle itYes it about escaping. Sequelize must generate sql:
ALTER TABLE `billing_apple_callback` CHANGE `timestamp` `updated_timestamp` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP;
But he generate wrong sql:
ALTER TABLE `billing_apple_callback` CHANGE `timestamp` `updated_timestamp` DATETIME NOT NULL DEFAULT \'CURRENT_TIMESTAMP\';