question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

On renameColumn throw error if defaultValue CURRENT_TIMESTAMP

See original GitHub issue

What 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:open
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
sushantdhimancommented, Jan 11, 2018

I think you have set defaultValue for this attribute to CURRENT_TIMESTAMP, remove that and let Sequelize handle it

1reaction
usebazcommented, Jan 11, 2018

Yes 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\';

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found