Home >Database >Mysql Tutorial >Can MySQL TEXT Columns Have Default Values?

Can MySQL TEXT Columns Have Default Values?

Susan Sarandon
Susan SarandonOriginal
2024-12-19 01:03:08570browse

Can MySQL TEXT Columns Have Default Values?

Default Values for TEXT Columns in MySQL

Question:
Why is it not possible to assign default values to TEXT columns in MySQL?

Answer:

Contrary to the given statement, assigning default values to TEXT columns is allowable in MySQL. However, due to a discrepancy between Windows and other operating systems, this action triggers an error on Windows platforms.

While Linux and other platforms raise a warning for this behavior, Windows MySQL v5 throws an error. This inconsistency arises from differences in MySQL's sql-mode settings.

Resolution:

To disable strict mode in MySQL 5 (Windows) and allow default values for TEXT columns, follow these steps:

  1. Edit the /my.ini file and locate the line:

    sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
  2. Replace it with:

    sql_mode='MYSQL40'
  3. Restart the MySQL service (net stop mysql5 and net start mysql5).

Alternatively, if you have root/admin access, you can execute the following query:

mysql_query("SET @@global.sql_mode='MYSQL40'");

The above is the detailed content of Can MySQL TEXT Columns Have Default Values?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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