Skip to content

Alter table doesn't work when timestamp column has a NOT NULL constraint #459

Answered by orware
okrsnak asked this question in Bug Reports
Discussion options

You must be logged in to vote

Hello @okrsnak,

I took a closer look here on this one for and I believe I have a solution that I can share.

It appears that either of the following should work for your needs:

ALTER TABLE `news`
	MODIFY COLUMN `id` varchar(256) NOT NULL,
	MODIFY COLUMN `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
	MODIFY COLUMN `updated_at` timestamp NOT NULL DEFAULT current_timestamp();
	
ALTER TABLE `news`
	MODIFY COLUMN `id` varchar(256) NOT NULL,
	MODIFY COLUMN `created_at` timestamp NOT NULL DEFAULT (now()),
	MODIFY COLUMN `updated_at` timestamp NOT NULL DEFAULT (now());

Interestingly, I was wondering if you had come across this situation when using our deploy request process initiall…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@okrsnak
Comment options

Answer selected by okrsnak
Comment options

You must be logged in to vote
3 replies
@orware
Comment options

@saborrie
Comment options

@orware
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants