[jifty-devel] jifty beginner problem

Sterling Hanenkamp sterling at hanenkamp.com
Tue Oct 14 08:34:32 EDT 2008


On Tue, Oct 14, 2008 at 5:18 AM, xu zhou <redicaps at gmail.com> wrote:

> WARN - DBD::mysql::st execute failed: BLOB/TEXT column 'title' can't
> have a default value at
> /usr/local/share/perl/5.8.8/Jifty/DBI/Handle.pm line 554.


If you use MySQL for database storage, don't use a default for text columns.
So, if your model definition looks like this:

column title => type is 'text', default is 'Untitled post';

You should change it to:

column title => type is 'text';

or to use a VARCHAR type instead like:

column title => type is 'varchar(100)', default is 'Untitled post';

If you still want the default and still want to use the "text" type, you can
add a before_create() hook to your model like this:

sub before_create {
    my ($self, $args) = @_;

    $args->{title} ||= 'Untitled post';

    return 1;
}

I think Jifty::DBI ought to be smart enough to know about and do the right
thing in this case, but it currently does not, so you'll have to go ahead
and take care of it this way for the time being.

Cheers,
Sterling


>
> WARN - Mywebblog::Handle=HASH(0x9f5abbc) couldn't execute the query
> 'CREATE TABLE posts (
>  id INTEGER NOT NULL  AUTO_INCREMENT,
>  title text NULL DEFAULT 'Untitled post' ,
>  body text NULL  ,
>  PRIMARY KEY (id)
> )
> ' at /usr/local/share/perl/5.8.8/Jifty/DBI/Handle.pm line 578.
> error creating table Mywebblog::Model::Post: Couldn't execute the
> query 'CREATE TABLE posts (
>  id INTEGER NOT NULL  AUTO_INCREMENT,
>  title text NULL DEFAULT 'Untitled post' ,
>  body text NULL  ,
>  PRIMARY KEY (id)
> )
> 'BLOB/TEXT column 'title' can't have a default value at
> /usr/local/share/perl/5.8.8/Jifty/Record.pm line 699.
>
> No tables were created in the database mywebblog
> Dose anybody know what is the problem?
> _______________________________________________
> jifty-devel mailing list
> jifty-devel at lists.jifty.org
> http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jifty.org/pipermail/jifty-devel/attachments/20081014/ceb12770/attachment.htm 


More information about the jifty-devel mailing list