So, in the Drupal 6 version of a lot of my modules, I made prodigious use of the datetime column type. Now, Drupal 7 says those pesky data-specific column types are off-limits. I created a hook_update_N function to convert datetime columns into char columns that looks like this:
function hook_update_N() { db_change_field( "foo", "column_1", "column_1", array( "type" => "char", "length" => 20, "not null" => true, "default" => "0000-00-00 00:00:00", ) );
db_change_field( "foo", "column_2", "column_2", array( "type" => "char", "length" => 20, "not null" => true, "default" => "0000-00-00 00:00:00", ) ); }
And when I run update.php, I now get:
Failed: PDOException: SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'column_2': ALTER TABLE {foo} CHANGE `created_on` `column_1` CHAR(20) NOT NULL DEFAULT '0000-00-00 00:00:00'; Array ( ) in db_change_field() (line 2984 of includes/database/database.inc).
Please not that it's complaining about the default value on column_2 when it's trying to update column_1.
How does one convert a table with two or more datetime columns to char(20) columns in Drupal 7?
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Tim Gustafson tjg@soe.ucsc.edu Baskin School of Engineering 831-459-5354 UC Santa Cruz Baskin Engineering 317B -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-