소스 검색

生成migration文件string类型如果是非nullable则默认设置默认值为空字符串

jqh 5 년 전
부모
커밋
d4b3cf5b8d
1개의 변경된 파일10개의 추가작업 그리고 5개의 파일을 삭제
  1. 10 5
      src/Scaffold/MigrationCreator.php

+ 10 - 5
src/Scaffold/MigrationCreator.php

@@ -86,16 +86,21 @@ class MigrationCreator extends BaseMigrationCreator
                 $column .= "->{$field['key']}()";
             }
 
-            if (isset($field['default']) && $field['default']) {
+            $hasDefault = isset($field['default'])
+                && ! is_null($field['default'])
+                && $field['default'] !== '';
+            if ($hasDefault) {
                 $column .= "->default('{$field['default']}')";
             }
 
-            if (isset($field['comment']) && $field['comment']) {
-                $column .= "->comment('{$field['comment']}')";
-            }
-
             if (Arr::get($field, 'nullable') == 'on') {
                 $column .= '->nullable()';
+            } elseif (! $hasDefault && $field['type'] === 'string') {
+                $column .= "->default('')";
+            }
+
+            if (isset($field['comment']) && $field['comment']) {
+                $column .= "->comment('{$field['comment']}')";
             }
 
             $rows[] = $column.";\n";