瀏覽代碼

生成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";