ERROR WHEN CREATING FIELD WITH DATA TO MYSQL PHPMYADMIN (1 & 1 hosting)

0

When creating the field dateee I get an error, and that is when I put the datatype ...

I'm using a paid hosting sql (1 & 1) and it creates conflict with a sql statement ..

The sentence:

ALTER TABLE publicaciones
ADD dateee DATETIME DEFAULT CURRENT_TIMESTAMP;

Error:

  

1067 - Invalid default value for 'dateee'

    
asked by Juliian68 06.11.2017 в 16:04
source

1 answer

0

The error is due to the fact that you are probably using a MySQL version prior to 5.6.5. If you can update it, this will eliminate your error.

Reference: link .

  

As of MySQL 5.6.5, TIMESTAMP and DATETIME columns can be automatically initialized and updated to the current date and time (that is, the current timestamp). Before 5.6.5, this is true only for TIMESTAMP , and for at most one TIMESTAMP column per table.

Translation:

  

As of MySQL 5.6.5, columns of type TIMESTAMP and DATETIME can be initialized and updated automatically with the current date and time (ie the current timestamp). Before 5.6.5, this could only be done with TIMESTAMP , and only with a maximum of one column of type TIMESTAMP per table.

If you can not update your MySQL, I think you only have 2 options:

  • Change the type of your column to TIMESTAMP .
  • Use a trigger to update the field with the current date and time.
  • answered by 06.11.2017 в 18:01