0

I am trying to create mysql table in PhpMyAdmin in Hostgator server with the following information but it is showing error

Error : #1067 - Invalid default value for 'CreatedDate'

Table

  CREATE TABLE `tbl_sample` (
  `ID` int(11) NOT NULL  AUTO_INCREMENT,
  `Domain` varchar(100) DEFAULT NULL,
  `ClickUrl` varchar(600) DEFAULT NULL,
  `CreatedDate` datetime NULL DEFAULT now(),
  `ModifyDate` timestamp NULL DEFAULT NULL on update now(),
  PRIMARY KEY (`ID`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

The purpose of table is I need to enter only 'Domain' and 'ClickUrl' data using insert command remaining Id(autoincrement),CreatedDate(current date when inserting row),ModifyDate(when update the row) will automatically insert.

The above table is executed successfully in mysql environment in my local system but it is not executing in the mysql environment in hostgator

3
  • now() is not an acceptable default value for a datetime, see stackoverflow.com/questions/5818423/… Jun 17, 2014 at 8:33
  • CreatedDate timestamp NULL DEFAULT now(), should use timestamp if you want to default value is now Jun 17, 2014 at 8:35
  • But two timestamp s in single table is not accepting in Mysql environment in hostgator it is showing error @SamarHaider
    – Surya
    Jun 17, 2014 at 8:38

1 Answer 1

1

Check this link]1

Problem with creating Two column with timestamps. have to use trigger to get it done.

5
  • I execute the exact script as mentioned above but it is showing the following error: #1067 - Invalid default value for 'CreatedDate' @user2767299
    – Surya
    Jun 17, 2014 at 8:42
  • what is version of your mySQl ? is it 5.6.5 ?
    – H. Mahida
    Jun 17, 2014 at 8:49
  • Thanks for your quick reply, The verion is : 5.5.37, I try with your new code but no luck, the error is : #1067 - Invalid default value for 'ModifyDate'
    – Surya
    Jun 17, 2014 at 9:25
  • Try this , think this error because we r tyringto insert NULL in timetamp ....try removing null as ....ModifyDate timestamp DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP
    – H. Mahida
    Jun 17, 2014 at 9:30
  • Sorry I need to specify you before, here we have no posibility to use two timestamps in single table, if we use the error rise : #1293 - Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
    – Surya
    Jun 17, 2014 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.