0

I was trying to create a table in mysql using phpmysqladmin but it is throwing the error "#1067 - Invalid default value for 'end_time"

My table structure below:

DROP TABLE IF EXISTS `apply_job`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
 SET character_set_client = utf8mb4 ;
CREATE TABLE `apply_job` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `job_id` int(11) NOT NULL,
  `apply_status` int(11) NOT NULL COMMENT '1-interested,2-complete assessment',
  `score` int(11) NOT NULL,
  `start_time` timestamp NOT NULL,
  `end_time` timestamp NOT NULL,
  `datetime` datetime(5) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3063 DEFAULT CHARSET=latin1;
  • I solve it in this way [https://stackoverflow.com/questions/36882149/error-1067-42000-invalid-default-value-for-created-at](https://stackoverflow.com/questions/36882149/error-1067-42000-invalid-default-value-for-created-at) – doctor_cap Mar 29 '21 at 07:08
  • `end_time` definition does not contain default value really. If the `explicit_defaults_for_timestamp system` variable is disabled, the first TIMESTAMP column has implicit both DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP if neither is specified explicitly. The second TIMESTAMP column have no such implicit definition which, in combination of NOT NULL, causes the problem. Swap `start_time` and `end_time` - and the error message will report the same about `start_time` column... In general it is a bad practice when you create NOT NULL column which have no default value. – Akina Mar 29 '21 at 07:32

0 Answers0