@@ -3693,16 +3693,17 @@ protected function get_column_definitions( $table_name, $columns ) {
36933693 $ auto_increment_column = $ this ->get_autoincrement_column ( $ table_name );
36943694 $ column_definitions = array ();
36953695 foreach ( $ columns as $ column ) {
3696+ $ mysql_type = $ this ->get_cached_mysql_data_type ( $ table_name , $ column ->name );
36963697 $ is_auto_incr = $ auto_increment_column && strtolower ( $ auto_increment_column ) === strtolower ( $ column ->name );
36973698 $ definition = array ();
36983699 $ definition [] = '` ' . $ column ->name . '` ' ;
3699- $ definition [] = $ this -> get_cached_mysql_data_type ( $ table_name , $ column -> name ) ?? $ column ->name ;
3700+ $ definition [] = $ mysql_type ?? $ column ->name ;
37003701
37013702 if ( '1 ' === $ column ->notnull ) {
37023703 $ definition [] = 'NOT NULL ' ;
37033704 }
37043705
3705- if ( null !== $ column -> dflt_value && '' !== $ column-> dflt_value && ! $ is_auto_incr ) {
3706+ if ( $ this -> column_has_default ( $ column, $ mysql_type ) && ! $ is_auto_incr ) {
37063707 $ definition [] = 'DEFAULT ' . $ column ->dflt_value ;
37073708 }
37083709
@@ -3858,6 +3859,22 @@ function ( $row ) use ( $name_map ) {
38583859 );
38593860 }
38603861
3862+ /**
3863+ * Checks if column should define the default.
3864+ *
3865+ * @param stdClass $column The table column
3866+ * @param string $mysql_type The MySQL data type
3867+ *
3868+ * @return boolean If column should have a default definition.
3869+ */
3870+ private function column_has_default ( $ column , $ mysql_type ) {
3871+ if ( null !== $ column ->dflt_value && '' !== $ column ->dflt_value && ! in_array ( strtolower ( $ mysql_type ), array ( 'datetime ' , 'date ' , 'time ' , 'timestamp ' , 'year ' ), true ) ) {
3872+ return true ;
3873+ }
3874+
3875+ return false ;
3876+ }
3877+
38613878 /**
38623879 * Consumes data types from the query.
38633880 *
0 commit comments