Home >Database >Mysql Tutorial >Can MySQL TEXT Columns Have Default Values?
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:
Edit the /my.ini file and locate the line:
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Replace it with:
sql_mode='MYSQL40'
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!