Home > Database > Mysql Tutorial > Why Am I Getting an 'Invalid Default Value' Error When Adding a Text Column to My Table?

Why Am I Getting an 'Invalid Default Value' Error When Adding a Text Column to My Table?

Linda Hamilton
Release: 2024-12-02 16:57:10
Original
119 people have browsed it

Why Am I Getting an

Invalid Default Value Error in Table Alteration

When attempting to modify your table by adding a new column, you encountered an error: "ERROR 1067 (42000): Invalid default value for 'created_at'". Despite googling, you discovered that this error typically arises during timestamp alteration. However, your situation involves adding a new text column named "bank."

To resolve this issue, you must verify your sql_modes. Use the following command:

show variables like 'sql_mode' ; 
Copy after login

If you notice the presence of "NO_ZERO_IN_DATE,NO_ZERO_DATE" in your sql_modes, this is causing the problem. Disable these modes to allow your query to succeed.

To globally modify the sql_mode as a root user, execute the following command:

set global sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
Copy after login

Once you have disabled the problematic sql_modes, you should be able to successfully add the "bank" column to your investments table.

The above is the detailed content of Why Am I Getting an 'Invalid Default Value' Error When Adding a Text Column to My Table?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template