[Dbix-class] Inserting empty string into DATETIME field in MySQL

Peter Wood pwood at christianbook.com
Mon Oct 10 20:25:58 GMT 2011

Thanks! That worked. I just added...

	$value = undef if ! $value;

...before I ran the insert/update, and it correctly inserted a null string.

-----Original Message-----
From: Ben Tilly <btilly at gmail.com>
Reply-To: "DBIx::Class user and developer list"
<dbix-class at lists.scsys.co.uk>
Date: Mon, 10 Oct 2011 11:42:56 -0700
To: "DBIx::Class user and developer list" <dbix-class at lists.scsys.co.uk>
Subject: Re: [Dbix-class] Inserting empty string into DATETIME field in

>The date you're getting is what you tend to get when MySQL sees that
>there should be a value but can't parse the result.
>Try passing in undef instead of an empty string and see if it works right.
>On Mon, Oct 10, 2011 at 11:30 AM, Peter Wood <pwood at christianbook.com>
>> Hello,
>> I'm trying to insert an empty string into a datetime field in MySQL
>> 5.0.18, using DBIx::Class version 0.08120. This particular field is
>> like so, within a call to 'add_columns':
>> __PACKAGE__->add_columns(
>> ..snip..
>> "start_date",
>>   {
>>     data_type => "DATETIME",
>>     default_value => undef,
>>     is_nullable => 1,
>>     size => 19,
>>   },
>> ..snip..
>> );
>> If I provide a complete value for start_date (eg 2011-10-10 14:29:27),
>> everything works fine. However, when I try to set it to the empty string
>> (''), the value inserted in the database is '0000-00-00 00:00:00'. If I
>> an insert on the command-line mysql client, and provide the empty
>>string as
>> the value for that field, it properly sets an empty value in the
>> Is there something else I should be doing to properly insert an empty
>> into this column?
>> Thanks,
>> Peter
>> _______________________________________________
>> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
>> IRC: irc.perl.org#dbix-class
>> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
>> Searchable Archive:
>> http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
>IRC: irc.perl.org#dbix-class
>SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
>Searchable Archive:

More information about the DBIx-Class mailing list