LMSouq
general-dev AI Answered

Set NOW() as Default Value for datetime datatype?

IB
Ibrahim Azhar Armar
1 month ago
3 views
Problem Description
I have two columns in table users namely `registerDate and lastVisitDate` which consist of datetime data type. I would like to do the following. 1. Set registerDate defaults value to MySQL NOW() 2. Set lastVisitDate default value to `0000-00-00 00:00:00` Instead of null which it uses by default. Because the table already exists and has existing records, I would like to use Modify table. I've tried using the two piece of code below, but neither works. ALTER TABLE users MODIFY registerDate datetime DEFAULT NOW() ALTER TABLE users MODIFY registerDate datetime DEFAULT CURRENT_TIMESTAMP; It gives me Error : `ERROR 1067 (42000): Invalid default value for 'registerDate'` Is it possible for me to set the default datetime value to NOW() in MySQL?

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base