Subject: | wrong default values from MySQL |
Loading a schema from MySQL can result in columns like this:
"id_foo", { data_type => "integer", default_value => "", ... },
...which doesn't make much sense: Integer columns cannot have a string
as defalt value. What I do to fix this is to pre-process the column
info, before running "deploy()" on the schema:
for my $source_name ($schema->sources) {
my $source = $schema->source($source_name);
my @pk = $source->primary_columns;
for my $col_name ($source->columns) {
my $col_info = $source->column_info($col_name) or next;
unless($col_info->{'data_type'} =~ /varchar/i) {
if(defined $col_info->{'default_value'} and $col_info-
Show quoted text
>{'default_value'} eq '') {
delete $col_info->{'default_value'};
}
}
}
}
$schema->deploy;
This seems to happen if a column has "NOT NULL" but no "DEFAULT":
CREATE TABLE bar (
id_foo int(10) NOT NULL,
);