カテゴリー
Linux

Xethron/migrations-generator で生成された内容で注意する点

まとめ

環境

  • MySQL 8.0.15
  • Laravel Framework 5.5.45
  • Laravel Migrations Generator v2.0.2

修正した例

text メソッドから mediumText, longText メソッドへの修正例

$ git diff
diff --git a/database/migrations/2019_06_02_062600_create_wp_commentmeta_table.php b/database/migrations/2019_06_02_062600_create_wp_commentmeta_table.php
index 5a1ba54..2e65b8d 100644
--- a/database/migrations/2019_06_02_062600_create_wp_commentmeta_table.php
+++ b/database/migrations/2019_06_02_062600_create_wp_commentmeta_table.php
@@ -17,7 +17,7 @@ class CreateWpCommentmetaTable extends Migration {
                        $table->bigInteger('meta_id', true)->unsigned();
                        $table->bigInteger('comment_id')->unsigned()->default(0)->index('comment_id');
                        $table->string('meta_key')->nullable()->index('meta_key');
-                       $table->text('meta_value')->nullable();
+                       $table->longText('meta_value')->nullable();
                });
        }

diff --git a/database/migrations/2019_06_02_062600_create_wp_links_table.php b/database/migrations/2019_06_02_062600_create_wp_links_table.php
index bc8b7fe..f7aa5a1 100644
--- a/database/migrations/2019_06_02_062600_create_wp_links_table.php
+++ b/database/migrations/2019_06_02_062600_create_wp_links_table.php
@@ -25,7 +25,7 @@ class CreateWpLinksTable extends Migration {
                        $table->integer('link_rating')->default(0);
                        $table->dateTime('link_updated')->default('0001-01-01 00:00:00');
                        $table->string('link_rel')->default('');
-                       $table->text('link_notes', 16777215);
+                       $table->mediumText('link_notes', 16777215);
                        $table->string('link_rss')->default('');
                });
        }
... 以下略 ...

text メソッドの第 2 引数を取り除いた修正例

$ git diff
diff --git a/database/migrations/2019_06_02_062600_create_wp_comments_table.php b/database/migrations/2019_06_02_062600_create_wp_comments_table.php
index 246e8c6..324f84b 100644
--- a/database/migrations/2019_06_02_062600_create_wp_comments_table.php
+++ b/database/migrations/2019_06_02_062600_create_wp_comments_table.php
@@ -22,7 +22,7 @@ class CreateWpCommentsTable extends Migration {
                        $table->string('comment_author_IP', 100)->default('');
                        $table->dateTime('comment_date')->default('0001-01-01 00:00:00');
                        $table->dateTime('comment_date_gmt')->default('0001-01-01 00:00:00')->index('comment_date_gmt');
-                       $table->text('comment_content', 65535);
+                       $table->text('comment_content');
                        $table->integer('comment_karma')->default(0);
                        $table->string('comment_approved', 20)->default('1');
                        $table->string('comment_agent')->default('');
diff --git a/database/migrations/2019_06_02_062600_create_wp_links_table.php b/database/migrations/2019_06_02_062600_create_wp_links_table.php
index f7aa5a1..094834e 100644
--- a/database/migrations/2019_06_02_062600_create_wp_links_table.php
+++ b/database/migrations/2019_06_02_062600_create_wp_links_table.php
@@ -25,7 +25,7 @@ class CreateWpLinksTable extends Migration {
                        $table->integer('link_rating')->default(0);
                        $table->dateTime('link_updated')->default('0001-01-01 00:00:00');
                        $table->string('link_rel')->default('');
-                       $table->mediumText('link_notes', 16777215);
+                       $table->mediumText('link_notes');
                        $table->string('link_rss')->default('');
                });
        }
... 以下略 ...

おわりに

マイグレーション後、シーダーを実行して次のエラーとなったために今回の件に気がつくことができました。

SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column ‘option_value’ at row 121

Laravel Migrations Generator はあくまでも補助ツールであって、生成後はしっかりと確認する方が望ましいですね♪

以上です。

コメントを残す