Unable to set a default serialized array using dbdelta()

You’re right that the problem is a result of the explode on semi-colons. We can use the dbdelta_queries filter to fix it.

In this solution we’re assuming that all queries start with CREATE, INSERT or UPDATE. If you have queries you’re running through dbDelta where this isn’t the case, the preg_match line will need adjusting or it won’t work correctly.

add_filter( 'dbdelta_queries', 'my_dbDelta_queries' );

function my_dbDelta_queries( $queries ) {

    $toJoin = array();
    $start  = array();
    $count  = 0;
        foreach( $queries as $i => $query ) :
                if ( !preg_match( "/CREATE|INSERT|UPDATE( [^ ]*)/", $query ) ) :
                        if( !empty( $start ) ) :
                            $toJoin[$count] = array( $start[key( $start )] );
                            unset( $queries[key( $start )] );
                        endif;
                    $toJoin[$count][] = $query;
                    unset( $queries[$i] );
                    $start = array();
                else :
                    $start = array( $i => $query );
                    $count++;
                endif;
        endforeach;

        if( !empty( $toJoin ) ) :
                foreach( $toJoin as $join ) :
                    $queries[] = implode( ';', $join );
                endforeach;
        endif;
    return $queries;

}

error code: 523