table.timestamps() should set ON UPDATE CURRENT_TIMESTAMP for updated_ts
See original GitHub issueExpected:
When creating the updated_ts column in table.timestamps(), its DDL should be:
timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
Actual:
The ON UPDATE CURRENT_TIMESTAMP part is missing - the updated_ts column is never autoupdated.
The syntax I’m describing works for MySQL, I’m not sure how compatible across database engines it is.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:42
- Comments:19 (5 by maintainers)
Top Results From Across the Web
11.2.5 Automatic Initialization and Updating for ...
With an ON UPDATE CURRENT_TIMESTAMP clause and a constant DEFAULT clause, the column is automatically updated to the current timestamp and has the...
Read more >mysql - When is a timestamp (auto) updated?
in it. DEFAULT CURRENT_TIMESTAMP means that any INSERT without an explicit time stamp setting uses the current time. Likewise, ON UPDATE CURRENT_TIMESTAMP means ......
Read more >Why $table->timestamps() puts 'ON UPDATE ...
I traced the problem and found ON UPDATE CURRENT_TIMESTAMP is set on the created_at column. After I disabled that, the code only update...
Read more >Automatically updating a timestamp column in PostgreSQL ...
This will create a table with the name user_task with columns created_on, updated_on, and status. Created_on and Updated_on are by default ...
Read more >Sequelize timestamps option and format explained
When you sync() the above model, the generated CREATE TABLE ... while the updatedAt column will store a timestamp of when the row...
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

Instead of relying on bookshelf you can create the datetime-fields manually (mysql):
Or if you prefer
updated_atto default to creation time as well:I think
timestamps()needs to either provide this auto-update functionality or the docs need to explicitly state that it does not. I simply assumed that functionality was a critical reason for why thetimestamps()method exists at all.