MySQL Alter Table – How to Change TIMESTAMP to TIMESTAMP(3)

alter-tableMySQLtimestamp

I have a column of TIMESTAMP, NOT NULL, DEFAULT CURRENT_TIMESTAMP.

I want to modify it as TIMESTAMP(3).

I tried

ALTER TABLE <table>
MODIFY COLUMN <column>
TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

And I got.

Error Code: 1067. Invalid default value for '<column>'

What can I do with it?

Best Answer

I'm answering for my own question.

I found an answer solves the exact problem.

https://stackoverflow.com/a/23671577/330457

Shortly, I needed to specify the same type for DEFAULT.

ALTER TABLE <table>
MODIFY COLUMN <column>
TIMESTAMP(3)
NOT NULL
DEFAULT CURRENT_TIMESTAMP(3) -- See?