<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[FrontAccounting forum — TEXT fields cannot have defaults]]></title>
		<link>https://frontaccounting.com/punbb/viewtopic.php?id=6841</link>
		<atom:link href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=6841&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in TEXT fields cannot have defaults.]]></description>
		<lastBuildDate>Wed, 21 Jun 2017 16:14:23 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[TEXT fields cannot have defaults]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=28052#p28052</link>
			<description><![CDATA[<p>In&nbsp; <strong>sql/alter2.4rc1.sql</strong>, the last line:<br /></p><div class="codebox"><pre><code>ALTER TABLE `0_sys_prefs` CHANGE `value` `value` text NOT NULL default &#039;&#039;;</code></pre></div><p>should have the default removed. In the standard Chart sqls corresponding changes must be effected.</p><p>MySQL does not allow any defaults for TINYTEXT, MEDIUMTEXT, LONGTEXT and TEXT fields.<br />Windows MySQL v5 throws an error but Linux and other versions only raise a warning.</p><p>Such TEXT fields do not support default values of anything but NULL. As such, it&#039;s implicitly DEFAULT NULL.</p><p>Use TRIGGERS to UPDATE such TEXT fields to <a href="https://stackoverflow.com/questions/3466872/why-cant-a-text-column-have-a-default-value-in-mysql">any desired default value</a>.<br /></p><div class="codebox"><pre><code>create table my_text

(
   abc text
);

delimiter //
create trigger mytext_trigger before insert on my_text
for each row
begin
   if (NEW.abc is null ) then
      set NEW.abc = &#039;default text&#039;;
   end if;
end
//
delimiter ;</code></pre></div><br /><p>No explanation is given by the MySQL documentation.</p><p>TEXT columns are for things which can become more than 255 bytes long.</p><div class="quotebox"><blockquote><p>On MS Windows the &quot;no DEFAULT&quot; rule is an error, while on other platforms it is often a warning. While not a bug, it&#039;s possible to get trapped by this if you write code on a lenient platform, and later run it on a strict platform.</p></blockquote></div><p><strong>How to disable strict mode in MySQL 5 (Windows):</strong></p><p>&nbsp; &nbsp; Edit /my.ini and look for line</p><p>&nbsp; &nbsp; sql-mode=&quot;STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION&quot;</p><p>&nbsp; &nbsp; Replace it with</p><p>&nbsp; &nbsp; sql_mode=&#039;MYSQL40&#039;</p><p>&nbsp; &nbsp; Restart the MySQL service (assuming that it is mysql5)</p><p>&nbsp; &nbsp; net stop mysql5<br />&nbsp; &nbsp; net start mysql5</p><p>If you have root/admin access you might be able to execute</p><p>mysql_query(&quot;SET @@global.sql_mode=&#039;MYSQL40&#039;&quot;);</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Wed, 21 Jun 2017 16:14:23 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=28052#p28052</guid>
		</item>
	</channel>
</rss>
