Database field of timestamp type cannot be added to the database using hook_schema() I have created a custom module in drupal 8. But in the .install file there is a field for created_date which has a type of timestamp. When I try to enable that module it gives the below error.

exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'created_date'' in


.install file

&lt;?php
function golf_reservation_schema()
{
  $schema['golf_reservation'] = array(
   'fields' =&gt; array(
       'id' =&gt; array(
           'type'     =&gt; 'serial',
           'not null' =&gt; TRUE,
       ),
       'property_tid' =&gt; array(
           'type' =&gt; 'int',
           'not null' =&gt; TRUE,
       ),
       'property_name' =&gt; array(
           'type'     =&gt; 'varchar',
           'length'   =&gt; 100,
           'not null' =&gt; TRUE,
       ),
       'title' =&gt; array(
           'type'     =&gt; 'varchar',
           'length'   =&gt; 20,
           'not null' =&gt; FALSE,
       ),
       'full_name' =&gt; array(
           'type'     =&gt; 'varchar',
           'length'   =&gt; 255,
           'not null' =&gt; TRUE,
       ),
       'tee_date' =&gt; array(
           'type'     =&gt; 'varchar',
           'length'   =&gt; 255,
           'not null' =&gt; TRUE,
       ),
       'tee_time' =&gt; array(
           'type'     =&gt; 'varchar',
           'length'   =&gt; 255,
           'not null' =&gt; TRUE,
       ),
       'golfers' =&gt; array(
           'type'     =&gt; 'int',
           'not null' =&gt; TRUE,
       ),
       'no_of_carts' =&gt; array(
           'type'     =&gt; 'int',
           'not null' =&gt; TRUE,
       ),
       'special_request' =&gt; array(
           'type'     =&gt; 'text',
           'not null' =&gt; FALSE,
       ),
       'created_date' =&gt; array(
           'mysql_type' =&gt; 'timestamp',
           'not null' =&gt; true,
       ),
     ),
     'primary key' =&gt; array('id'),
   );

   return $schema;
}


But when I execute this query in database it does not give an error

CREATE TABLE eme_golf_reservation (
  `id` INT NOT NULL auto_increment, 
  `property_tid` INT NOT NULL, 
  `property_name` VARCHAR(100) NOT NULL, 
  `title` VARCHAR(20) NULL DEFAULT NULL, 
  `full_name` VARCHAR(255) NOT NULL, 
  `tee_date` VARCHAR(255) NOT NULL, 
  `tee_time` VARCHAR(255) NOT NULL, 
  `golfers` INT NOT NULL, 
  `no_of_carts` INT NOT NULL, 
  `special_request` TEXT NULL DEFAULT NULL, 
  `created_date` TIMESTAMP NOT NULL, 
  PRIMARY KEY (`id`)
)


I am running the latest Drupal version with MySQL 5.6.30.
I believe you need to explicitly define the default value for those in the schema:

'created_date' =&gt; [
  'mysql_type' =&gt; 'timestamp',
  'not null' =&gt; FALSE,
  'default' =&gt; NULL,
],


For maximum portability, you can also define the types for other databases:

'created_date' =&gt; [
  'mysql_type' =&gt; 'timestamp',
  'pgsql_type' =&gt; 'timestamp',
  'sqlite_type' =&gt; 'datetime',
  'not null' =&gt; FALSE,
  'default' =&gt; NULL,
],


Look at \Drupal\KernelTests\Core\Database\SchemaTest for an example.  FWIW, code doesn't use that for timestamp/created/updated.  Those are field types and handled by the Field API.