{"id":2655,"date":"2025-03-24T08:46:51","date_gmt":"2025-03-23T23:46:51","guid":{"rendered":"https:\/\/dexall.co.jp\/articles\/?p=2655"},"modified":"2025-03-24T08:47:19","modified_gmt":"2025-03-23T23:47:19","slug":"%e3%80%90%e4%bf%9d%e5%ad%98%e7%89%88%e3%80%91laravel-migration%e3%81%a7%e3%82%ab%e3%83%a9%e3%83%a0%e8%bf%bd%e5%8a%a0%e3%82%92%e5%ae%8c%e5%85%a8%e3%83%9e%e3%82%b9%e3%82%bf%e3%83%bc%ef%bc%815%e3%81%a4","status":"publish","type":"post","link":"https:\/\/dexall.co.jp\/articles\/?p=2655","title":{"rendered":"\u3010\u4fdd\u5b58\u7248\u3011Laravel Migration\u3067\u30ab\u30e9\u30e0\u8ffd\u52a0\u3092\u5b8c\u5168\u30de\u30b9\u30bf\u30fc\uff015\u3064\u306e\u5b9f\u8df5\u30d1\u30bf\u30fc\u30f3\u3068\u30c8\u30e9\u30d6\u30eb\u5bfe\u7b56"},"content":{"rendered":"\n<div class=\"toc\"><br \/>\n<b>Warning<\/b>:  Undefined array key \"is_admin\" in <b>\/home\/xs392991\/dexall.co.jp\/public_html\/articles\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>116<\/b><br \/>\n<br \/>\n<b>Warning<\/b>:  Undefined array key \"is_category_top\" in <b>\/home\/xs392991\/dexall.co.jp\/public_html\/articles\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>121<\/b><br \/>\n<br \/>\n<b>Warning<\/b>:  Undefined array key \"is_top\" in <b>\/home\/xs392991\/dexall.co.jp\/public_html\/articles\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>128<\/b><br \/>\n    <div id=\"toc_container\" class=\"sgb-toc--bullets js-smooth-scroll\" data-dialog-title=\"\u76ee\u6b21\">\n      <p class=\"toc_title\">\u76ee\u6b21 <\/p>\n      <ul class=\"toc_list\">  <li class=\"first\">    <a href=\"#i-0\">Laravel Migration\u3068\u306f\uff1f\u30ab\u30e9\u30e0\u8ffd\u52a0\u306e\u57fa\u790e\u77e5\u8b58<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-1\">\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u91cd\u8981\u6027\u3068\u5229\u70b9<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-2\">Laravel\u304c\u63d0\u4f9b\u3059\u308bMigration\u306e\u7279\u5fb4<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-3\">Laravel Migration\u3067\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\u3059\u308b\u57fa\u672c\u7684\u306a\u624b\u9806<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-4\">\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210\u65b9\u6cd5<\/a>      <\/li>      <li>        <a href=\"#i-5\">\u4e3b\u8981\u306a\u30ab\u30e9\u30e0\u30bf\u30a4\u30d7\u3068\u5c5e\u6027\u306e\u6307\u5b9a\u65b9\u6cd5<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-6\">\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u5b9f\u884c\u3068\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u306e\u624b\u9806<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-7\">\u5b9f\u8df5\u3067\u4f7f\u3048\u308b5\u3064\u306e\u30ab\u30e9\u30e0\u8ffd\u52a0\u30d1\u30bf\u30fc\u30f3<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-8\">1. \u5358\u7d14\u306a\u6587\u5b57\u5217\u30ab\u30e9\u30e0\u306e\u8ffd\u52a0<\/a>      <\/li>      <li>        <a href=\"#i-9\">2. \u5916\u90e8\u30ad\u30fc\u5236\u7d04\u4ed8\u304d\u30ab\u30e9\u30e0\u306e\u8ffd\u52a0<\/a>      <\/li>      <li>        <a href=\"#i-10\">3. Nullable\u306a\u4efb\u610f\u9805\u76ee\u306e\u8ffd\u52a0<\/a>      <\/li>      <li>        <a href=\"#i-11\">4. \u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u6301\u3064\u30ab\u30e9\u30e0\u306e\u8ffd\u52a0<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-12\">5. \u30e6\u30cb\u30fc\u30af\u5236\u7d04\u4ed8\u304d\u30ab\u30e9\u30e0\u306e\u8ffd\u52a0<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-13\">\u30ab\u30e9\u30e0\u8ffd\u52a0\u6642\u306e\u30c8\u30e9\u30d6\u30eb\u30b7\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-14\">\u3088\u304f\u3042\u308b\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3068\u305d\u306e\u89e3\u6c7a\u65b9\u6cd5<\/a>      <\/li>      <li>        <a href=\"#i-17\">\u5927\u898f\u6a21\u30c6\u30fc\u30d6\u30eb\u3067\u306e\u30ab\u30e9\u30e0\u8ffd\u52a0\u6642\u306e\u6ce8\u610f\u70b9<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-20\">\u672c\u756a\u74b0\u5883\u3067\u306e\u30ab\u30e9\u30e0\u8ffd\u52a0\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-24\">\u30c1\u30fc\u30e0\u958b\u767a\u306b\u304a\u3051\u308bMigration\u306e\u904b\u7528\u30c6\u30af\u30cb\u30c3\u30af<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-25\">\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u306e\u547d\u540d\u898f\u5247<\/a>      <\/li>      <li>        <a href=\"#i-28\">\u30b3\u30fc\u30c9\u30ec\u30d3\u30e5\u30fc\u3067\u30c1\u30a7\u30c3\u30af\u3059\u3079\u304d\u30dd\u30a4\u30f3\u30c8<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-32\">\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u5c65\u6b74\u306e\u7ba1\u7406\u65b9\u6cd5<\/a>      <\/li>    <\/ul>  <\/li>  <li class=\"last\">    <a href=\"#i-36\">\u30ab\u30e9\u30e0\u8ffd\u52a0\u306e\u5fdc\u7528\u30c6\u30af\u30cb\u30c3\u30af<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-37\">\u8907\u6570\u30ab\u30e9\u30e0\u306e\u4e00\u62ec\u8ffd\u52a0\u65b9\u6cd5<\/a>      <\/li>      <li>        <a href=\"#i-38\">\u6761\u4ef6\u4ed8\u304d\u3067\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\u3059\u308b\u65b9\u6cd5<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-39\">\u30ab\u30e9\u30e0\u8ffd\u52a0\u3068\u540c\u6642\u306b\u30c7\u30fc\u30bf\u3092\u8a2d\u5b9a\u3059\u308b\u65b9\u6cd5<\/a>      <\/li>    <\/ul>  <\/li><\/ul>\n      <a href=\"#\" class=\"sgb-toc-button js-toc-button\" rel=\"nofollow\" data-open-dialog=\"true\"><i class=\"fa fa-list\"><\/i><span class=\"sgb-toc-button__text\">\u76ee\u6b21\u3078<\/span><\/a>\n    <\/div><\/div><h2 class=\"wp-block-heading\" id=\"i-0\">Laravel Migration\u3068\u306f\uff1f\u30ab\u30e9\u30e0\u8ffd\u52a0\u306e\u57fa\u790e\u77e5\u8b58<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-1\">\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u91cd\u8981\u6027\u3068\u5229\u70b9<\/h3>\n\n\n\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u306f\u3001\u30e2\u30c0\u30f3\u306a\u958b\u767a\u30d7\u30ed\u30bb\u30b9\u306b\u304a\u3044\u3066\u4e0d\u53ef\u6b20\u306a\u8981\u7d20\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u7279\u306b\u30c1\u30fc\u30e0\u958b\u767a\u306b\u304a\u3044\u3066\u3001\u305d\u306e\u91cd\u8981\u6027\u306f\u9855\u8457\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u304c\u63d0\u4f9b\u3059\u308b\u4e3b\u306a\u5229\u70b9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30d0\u30fc\u30b8\u30e7\u30f3\u7ba1\u7406\u3068\u306e\u7d71\u5408<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30b9\u30ad\u30fc\u30de\u306e\u5909\u66f4\u5c65\u6b74\u3092Git\u306a\u3069\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u7ba1\u7406\u30b7\u30b9\u30c6\u30e0\u3067\u8ffd\u8de1\u53ef\u80fd<\/li>\n\n\n\n<li>\u30c1\u30fc\u30e0\u30e1\u30f3\u30d0\u30fc\u5168\u54e1\u304c\u540c\u3058\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u69cb\u9020\u3092\u5171\u6709\u3067\u304d\u308b<\/li>\n\n\n\n<li>\u5909\u66f4\u306e\u5dfb\u304d\u623b\u3057\u304c\u5bb9\u6613<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u74b0\u5883\u9593\u306e\u4e00\u8cab\u6027\u78ba\u4fdd<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u958b\u767a\u74b0\u5883\u3001\u30c6\u30b9\u30c8\u74b0\u5883\u3001\u672c\u756a\u74b0\u5883\u3067\u540c\u4e00\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u69cb\u9020\u3092\u4fdd\u8a3c<\/li>\n\n\n\n<li>\u74b0\u5883\u4f9d\u5b58\u306e\u30d0\u30b0\u3092\u65e9\u671f\u306b\u767a\u898b\u53ef\u80fd<\/li>\n\n\n\n<li>\u30c7\u30d7\u30ed\u30a4\u30e1\u30f3\u30c8\u30d7\u30ed\u30bb\u30b9\u306e\u81ea\u52d5\u5316\u304c\u5bb9\u6613<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30c1\u30fc\u30e0\u958b\u767a\u3067\u306e\u751f\u7523\u6027\u5411\u4e0a<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u5909\u66f4\u306e\u9069\u7528\u304c\u81ea\u52d5\u5316\u3055\u308c\u3001\u4eba\u7684\u30df\u30b9\u3092\u9632\u6b62<\/li>\n\n\n\n<li>\u65b0\u3057\u3044\u30c1\u30fc\u30e0\u30e1\u30f3\u30d0\u30fc\u306e\u74b0\u5883\u69cb\u7bc9\u304c\u5bb9\u6613<\/li>\n\n\n\n<li>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u69cb\u9020\u306e\u5909\u66f4\u5c65\u6b74\u304c\u6587\u66f8\u5316\u3055\u308c\u308b<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-2\">Laravel\u304c\u63d0\u4f9b\u3059\u308bMigration\u306e\u7279\u5fb4<\/h3>\n\n\n\n<p>Laravel\u306e\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u6a5f\u80fd\u306f\u3001PHP\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306e\u4e2d\u3067\u3082\u7279\u306b\u512a\u308c\u305f\u7279\u5fb4\u3092\u6301\u3063\u3066\u3044\u307e\u3059\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u76f4\u611f\u7684\u306a\u30b9\u30ad\u30fc\u30de\u5b9a\u7fa9<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   \/\/ \u30c6\u30fc\u30d6\u30eb\u4f5c\u6210\u306e\u4f8b\n   Schema::create('users', function (Blueprint $table) {\n       $table-&gt;id();                    \/\/ \u4e3b\u30ad\u30fc\u306e\u5b9a\u7fa9\n       $table-&gt;string('name');          \/\/ \u6587\u5b57\u5217\u30ab\u30e9\u30e0\u306e\u8ffd\u52a0\n       $table-&gt;string('email')-&gt;unique(); \/\/ \u30e6\u30cb\u30fc\u30af\u5236\u7d04\u4ed8\u304d\u30ab\u30e9\u30e0\n       $table-&gt;timestamps();            \/\/ created_at, updated_at\u30ab\u30e9\u30e0\u306e\u8ffd\u52a0\n   });<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u8c4a\u5bcc\u306a\u30ab\u30e9\u30e0\u30bf\u30a4\u30d7<\/strong><br>Laravel\u306f\u69d8\u3005\u306a\u30c7\u30fc\u30bf\u30bf\u30a4\u30d7\u306b\u5bfe\u5fdc\u3057\u305f\u30ab\u30e9\u30e0\u30e1\u30bd\u30c3\u30c9\u3092\u63d0\u4f9b\u3057\u3066\u3044\u307e\u3059\uff1a<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>string()<\/code>: VARCHAR\u578b\u30ab\u30e9\u30e0<\/li>\n\n\n\n<li><code>integer()<\/code>: INTEGER\u578b\u30ab\u30e9\u30e0<\/li>\n\n\n\n<li><code>text()<\/code>: TEXT\u578b\u30ab\u30e9\u30e0<\/li>\n\n\n\n<li><code>boolean()<\/code>: BOOLEAN\u578b\u30ab\u30e9\u30e0<\/li>\n\n\n\n<li><code>datetime()<\/code>: DATETIME\u578b\u30ab\u30e9\u30e0<br>\u306a\u3069<\/li>\n<\/ul>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u5f37\u529b\u306a\u5236\u7d04\u30b5\u30dd\u30fc\u30c8<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5916\u90e8\u30ad\u30fc\u5236\u7d04<\/li>\n\n\n\n<li>\u30e6\u30cb\u30fc\u30af\u5236\u7d04<\/li>\n\n\n\n<li>NULL\u5236\u7d04<\/li>\n\n\n\n<li>\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u306e\u8a2d\u5b9a<br>\u304c\u7c21\u5358\u306b\u5b9f\u88c5\u53ef\u80fd<\/li>\n<\/ul>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u6a5f\u80fd<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   \/\/ \u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u5dfb\u304d\u623b\u3057\u3082\u7c21\u5358\u306b\u5b9a\u7fa9\u53ef\u80fd\n   public function down()\n   {\n       Schema::dropIfExists('users');\n   }<\/pre>\n\n\n\n<ol start=\"5\" class=\"wp-block-list\">\n<li><strong>\u30b7\u30fc\u30c7\u30a3\u30f3\u30b0\u9023\u643a<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u306e\u6295\u5165\u304c\u5bb9\u6613<\/li>\n\n\n\n<li>\u74b0\u5883\u69cb\u7bc9\u306e\u81ea\u52d5\u5316\u3092\u30b5\u30dd\u30fc\u30c8<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u306e\u57fa\u76e4\u304c\u3042\u308b\u3053\u3068\u3067\u3001\u958b\u767a\u30c1\u30fc\u30e0\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u6069\u6075\u3092\u53d7\u3051\u3089\u308c\u307e\u3059\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u69cb\u9020\u306e\u5909\u66f4\u3092\u5b89\u5168\u306b\u7ba1\u7406<\/li>\n\n\n\n<li>\u8907\u6570\u74b0\u5883\u3067\u306e\u4e00\u8cab\u6027\u78ba\u4fdd<\/li>\n\n\n\n<li>\u30c7\u30d7\u30ed\u30a4\u30e1\u30f3\u30c8\u30d7\u30ed\u30bb\u30b9\u306e\u81ea\u52d5\u5316<\/li>\n\n\n\n<li>\u30c1\u30fc\u30e0\u5168\u4f53\u306e\u751f\u7523\u6027\u5411\u4e0a<\/li>\n<\/ul>\n\n\n\n<p>Laravel\u306e\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u6a5f\u80fd\u306f\u3001\u7279\u306b\u30ab\u30e9\u30e0\u306e\u8ffd\u52a0\u3084\u5909\u66f4\u306b\u304a\u3044\u3066\u3001\u958b\u767a\u8005\u306b\u512a\u308c\u305f\u67d4\u8edf\u6027\u3068\u5236\u5fa1\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001\u5177\u4f53\u7684\u306a\u30ab\u30e9\u30e0\u8ffd\u52a0\u306e\u624b\u9806\u306b\u3064\u3044\u3066\u8a73\u3057\u304f\u8aac\u660e\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-3\">Laravel Migration\u3067\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\u3059\u308b\u57fa\u672c\u7684\u306a\u624b\u9806<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-4\">\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210\u65b9\u6cd5<\/h3>\n\n\n\n<p>Laravel\u3067\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\u3059\u308b\u969b\u306e\u6700\u521d\u306e\u30b9\u30c6\u30c3\u30d7\u306f\u3001\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210\u3067\u3059\u3002\u3053\u308c\u306b\u306f<code>artisan<\/code>\u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u7528\u3057\u307e\u3059\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u57fa\u672c\u7684\u306a\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210\nphp artisan make:migration add_column_to_users_table\n\n# \u30c6\u30fc\u30d6\u30eb\u3068\u30ab\u30e9\u30e0\u3092\u6307\u5b9a\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u4f5c\u6210\nphp artisan make:migration add_phone_to_users_table --table=users<\/pre>\n\n\n\n<p>\u4f5c\u6210\u3055\u308c\u308b\u30d5\u30a1\u30a4\u30eb\u306f<code>database\/migrations<\/code>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u914d\u7f6e\u3055\u308c\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u57fa\u672c\u69cb\u9020\u3092\u6301\u3061\u307e\u3059\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Facades\\Schema;\n\nclass AddPhoneToUsersTable extends Migration\n{\n    public function up()\n    {\n        Schema::table('users', function (Blueprint $table) {\n            \/\/ \u3053\u3053\u306b\u30ab\u30e9\u30e0\u8ffd\u52a0\u306e\u30b3\u30fc\u30c9\u3092\u8a18\u8ff0\n        });\n    }\n\n    public function down()\n    {\n        Schema::table('users', function (Blueprint $table) {\n            \/\/ \u3053\u3053\u306b\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u6642\u306e\u51e6\u7406\u3092\u8a18\u8ff0\n        });\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-5\">\u4e3b\u8981\u306a\u30ab\u30e9\u30e0\u30bf\u30a4\u30d7\u3068\u5c5e\u6027\u306e\u6307\u5b9a\u65b9\u6cd5<\/h3>\n\n\n\n<p>Laravel\u3067\u306f\u3001\u69d8\u3005\u306a\u30ab\u30e9\u30e0\u30bf\u30a4\u30d7\u3068\u5c5e\u6027\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u57fa\u672c\u7684\u306a\u30ab\u30e9\u30e0\u30bf\u30a4\u30d7<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   Schema::table('users', function (Blueprint $table) {\n       $table-&gt;string('name', 100);        \/\/ VARCHAR(100)\n       $table-&gt;integer('age');             \/\/ INTEGER\n       $table-&gt;text('description');        \/\/ TEXT\n       $table-&gt;decimal('price', 8, 2);     \/\/ DECIMAL(8,2)\n       $table-&gt;datetime('published_at');   \/\/ DATETIME\n       $table-&gt;boolean('is_active');       \/\/ BOOLEAN\n   });<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u30ab\u30e9\u30e0\u4fee\u98fe\u5b50\uff08\u5c5e\u6027\uff09<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   Schema::table('users', function (Blueprint $table) {\n       $table-&gt;string('email')-&gt;unique();          \/\/ \u30e6\u30cb\u30fc\u30af\u5236\u7d04\n       $table-&gt;integer('points')-&gt;default(0);      \/\/ \u30c7\u30d5\u30a9\u30eb\u30c8\u5024\n       $table-&gt;string('phone')-&gt;nullable();        \/\/ NULL\u8a31\u53ef\n       $table-&gt;timestamp('deleted_at')-&gt;nullable();\/\/ \u30bd\u30d5\u30c8\u30c7\u30ea\u30fc\u30c8\u7528\n   });<\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3068\u5916\u90e8\u30ad\u30fc<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   Schema::table('posts', function (Blueprint $table) {\n       \/\/ \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u8ffd\u52a0\n       $table-&gt;string('slug')-&gt;index();\n\n       \/\/ \u5916\u90e8\u30ad\u30fc\u306e\u8a2d\u5b9a\n       $table-&gt;unsignedBigInteger('user_id');\n       $table-&gt;foreign('user_id')\n             -&gt;references('id')\n             -&gt;on('users')\n             -&gt;onDelete('cascade');\n   });<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-6\">\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u5b9f\u884c\u3068\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u306e\u624b\u9806<\/h3>\n\n\n\n<p>\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u5b9f\u884c\u3068\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u306f\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u884c\u3044\u307e\u3059\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u5b9f\u884c<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   # \u5168\u3066\u306e\u672a\u5b9f\u884c\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\n   php artisan migrate\n\n   # \u5f37\u5236\u5b9f\u884c\uff08\u672c\u756a\u74b0\u5883\u3067\u306e\u5b9f\u884c\u6642\uff09\n   php artisan migrate --force\n\n   # \u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u3057\u3066\u304b\u3089\u518d\u5b9f\u884c\n   php artisan migrate:refresh<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u64cd\u4f5c<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   # \u76f4\u524d\u306e\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\n   php artisan migrate:rollback\n\n   # \u7279\u5b9a\u306e\u30b9\u30c6\u30c3\u30d7\u6570\u3060\u3051\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\n   php artisan migrate:rollback --step=2\n\n   # \u5168\u3066\u306e\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\n   php artisan migrate:reset<\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u30b9\u30c6\u30fc\u30bf\u30b9\u78ba\u8a8d<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   # \u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u5b9f\u884c\u72b6\u6cc1\u3092\u78ba\u8a8d\n   php artisan migrate:status<\/pre>\n\n\n\n<p>\u5b9f\u884c\u6642\u306e\u91cd\u8981\u306a\u30dd\u30a4\u30f3\u30c8\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u672c\u756a\u74b0\u5883\u3067\u306e\u6ce8\u610f\u4e8b\u9805<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5fc5\u305a\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3092\u53d6\u5f97<\/li>\n\n\n\n<li>\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u30e2\u30fc\u30c9\u306e\u4f7f\u7528\u3092\u691c\u8a0e<\/li>\n\n\n\n<li><code>--force<\/code>\u30aa\u30d7\u30b7\u30e7\u30f3\u306e\u5fc5\u8981\u6027\u3092\u78ba\u8a8d<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5b9f\u884c\u524d\u306e\u30c1\u30a7\u30c3\u30af\u9805\u76ee<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u78ba\u8a8d<\/li>\n\n\n\n<li>\u65e2\u5b58\u30c7\u30fc\u30bf\u3078\u306e\u5f71\u97ff\u8a55\u4fa1<\/li>\n\n\n\n<li>\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u51e6\u7406\u306e\u52d5\u4f5c\u78ba\u8a8d<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30c8\u30e9\u30d6\u30eb\u767a\u751f\u6642\u306e\u5bfe\u5fdc<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30ed\u30b0\u306e\u78ba\u8a8d<\/li>\n\n\n\n<li>\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u30d7\u30e9\u30f3\u306e\u6e96\u5099<\/li>\n\n\n\n<li>\u30c1\u30fc\u30e0\u5185\u3067\u306e\u5171\u6709<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u57fa\u672c\u7684\u306a\u624b\u9806\u3092\u62bc\u3055\u3048\u308b\u3053\u3068\u3067\u3001\u5b89\u5168\u304b\u3064\u52b9\u7387\u7684\u306a\u30ab\u30e9\u30e0\u8ffd\u52a0\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001\u5b9f\u8df5\u7684\u306a\u30ab\u30e9\u30e0\u8ffd\u52a0\u30d1\u30bf\u30fc\u30f3\u306b\u3064\u3044\u3066\u8a73\u3057\u304f\u8aac\u660e\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-7\">\u5b9f\u8df5\u3067\u4f7f\u3048\u308b5\u3064\u306e\u30ab\u30e9\u30e0\u8ffd\u52a0\u30d1\u30bf\u30fc\u30f3<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-8\">1. \u5358\u7d14\u306a\u6587\u5b57\u5217\u30ab\u30e9\u30e0\u306e\u8ffd\u52a0<\/h3>\n\n\n\n<p>\u6700\u3082\u57fa\u672c\u7684\u306a\u30d1\u30bf\u30fc\u30f3\u3067\u3042\u308b\u6587\u5b57\u5217\u30ab\u30e9\u30e0\u306e\u8ffd\u52a0\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Facades\\Schema;\n\nclass AddNicknameToUsersTable extends Migration\n{\n    public function up()\n    {\n        Schema::table('users', function (Blueprint $table) {\n            \/\/ \u30b7\u30f3\u30d7\u30eb\u306a\u6587\u5b57\u5217\u30ab\u30e9\u30e0\u306e\u8ffd\u52a0\n            $table-&gt;string('nickname', 50)-&gt;after('name');\n\n            \/\/ \u8907\u6570\u30ab\u30e9\u30e0\u3092\u4e00\u5ea6\u306b\u8ffd\u52a0\u3059\u308b\u5834\u5408\n            $table-&gt;string('twitter_handle')-&gt;nullable()-&gt;after('nickname');\n            $table-&gt;string('facebook_id')-&gt;nullable()-&gt;after('twitter_handle');\n        });\n    }\n\n    public function down()\n    {\n        Schema::table('users', function (Blueprint $table) {\n            \/\/ \u8ffd\u52a0\u3057\u305f\u30ab\u30e9\u30e0\u306e\u524a\u9664\n            $table-&gt;dropColumn(['nickname', 'twitter_handle', 'facebook_id']);\n        });\n    }\n}<\/pre>\n\n\n\n<p><strong>\u30dd\u30a4\u30f3\u30c8<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>after()<\/code>\u30e1\u30bd\u30c3\u30c9\u3067\u8ffd\u52a0\u4f4d\u7f6e\u3092\u6307\u5b9a\u53ef\u80fd<\/li>\n\n\n\n<li>\u8907\u6570\u30ab\u30e9\u30e0\u306e\u4e00\u62ec\u8ffd\u52a0\u3082\u52b9\u7387\u7684<\/li>\n\n\n\n<li><code>down()<\/code>\u30e1\u30bd\u30c3\u30c9\u3067\u306f\u8ffd\u52a0\u306e\u9006\u306e\u64cd\u4f5c\u3092\u5b9a\u7fa9<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-9\">2. \u5916\u90e8\u30ad\u30fc\u5236\u7d04\u4ed8\u304d\u30ab\u30e9\u30e0\u306e\u8ffd\u52a0<\/h3>\n\n\n\n<p>\u4ed6\u306e\u30c6\u30fc\u30d6\u30eb\u3068\u95a2\u9023\u3092\u6301\u3064\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\u3059\u308b\u969b\u306e\u30d1\u30bf\u30fc\u30f3\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Facades\\Schema;\n\nclass AddDepartmentIdToEmployeesTable extends Migration\n{\n    public function up()\n    {\n        Schema::table('employees', function (Blueprint $table) {\n            \/\/ \u5916\u90e8\u30ad\u30fc\u30ab\u30e9\u30e0\u306e\u8ffd\u52a0\n            $table-&gt;unsignedBigInteger('department_id')-&gt;after('id');\n\n            \/\/ \u5916\u90e8\u30ad\u30fc\u5236\u7d04\u306e\u8a2d\u5b9a\n            $table-&gt;foreign('department_id')\n                  -&gt;references('id')\n                  -&gt;on('departments')\n                  -&gt;onDelete('restrict')\n                  -&gt;onUpdate('cascade');\n        });\n    }\n\n    public function down()\n    {\n        Schema::table('employees', function (Blueprint $table) {\n            \/\/ \u5916\u90e8\u30ad\u30fc\u5236\u7d04\u306e\u524a\u9664\uff08\u5236\u7d04\u540d\u3092\u6307\u5b9a\uff09\n            $table-&gt;dropForeign(['department_id']);\n            \/\/ \u30ab\u30e9\u30e0\u306e\u524a\u9664\n            $table-&gt;dropColumn('department_id');\n        });\n    }\n}<\/pre>\n\n\n\n<p><strong>\u91cd\u8981\u306a\u6ce8\u610f\u70b9<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u53c2\u7167\u5148\u306e\u30c6\u30fc\u30d6\u30eb\u304c\u5148\u306b\u5b58\u5728\u3057\u3066\u3044\u308b\u3053\u3068\u3092\u78ba\u8a8d<\/li>\n\n\n\n<li>\u9069\u5207\u306a<code>onDelete<\/code>\u3068<code>onUpdate<\/code>\u30a2\u30af\u30b7\u30e7\u30f3\u306e\u9078\u629e<\/li>\n\n\n\n<li>\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u6642\u306f\u5236\u7d04\u3092\u5148\u306b\u524a\u9664<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-10\">3. Nullable\u306a\u4efb\u610f\u9805\u76ee\u306e\u8ffd\u52a0<\/h3>\n\n\n\n<p>\u4efb\u610f\u5165\u529b\u9805\u76ee\u3068\u3057\u3066\u65b0\u3057\u3044\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\u3059\u308b\u30d1\u30bf\u30fc\u30f3\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Facades\\Schema;\n\nclass AddBioToUsersTable extends Migration\n{\n    public function up()\n    {\n        Schema::table('users', function (Blueprint $table) {\n            \/\/ NULL\u8a31\u5bb9\u306e\u6587\u5b57\u5217\u30ab\u30e9\u30e0\n            $table-&gt;string('bio')-&gt;nullable();\n\n            \/\/ NULL\u8a31\u5bb9\u306eJSON\u578b\u30ab\u30e9\u30e0\n            $table-&gt;json('preferences')-&gt;nullable();\n\n            \/\/ NULL\u8a31\u5bb9\u306e\u65e5\u6642\u30ab\u30e9\u30e0\n            $table-&gt;timestamp('last_login_at')-&gt;nullable();\n        });\n    }\n\n    public function down()\n    {\n        Schema::table('users', function (Blueprint $table) {\n            $table-&gt;dropColumn(['bio', 'preferences', 'last_login_at']);\n        });\n    }\n}<\/pre>\n\n\n\n<p><strong>\u5b9f\u88c5\u306e\u30dd\u30a4\u30f3\u30c8<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>nullable()<\/code>\u4fee\u98fe\u5b50\u306e\u4ed8\u4e0e\u3092\u5fd8\u308c\u306a\u3044<\/li>\n\n\n\n<li>\u65e2\u5b58\u30ec\u30b3\u30fc\u30c9\u3078\u306e\u5f71\u97ff\u3092\u8003\u616e<\/li>\n\n\n\n<li>\u9069\u5207\u306a\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u306e\u691c\u8a0e<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-11\">4. \u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u6301\u3064\u30ab\u30e9\u30e0\u306e\u8ffd\u52a0<\/h3>\n\n\n\n<p>\u65b0\u898f\u30ab\u30e9\u30e0\u8ffd\u52a0\u6642\u306b\u65e2\u5b58\u30ec\u30b3\u30fc\u30c9\u3078\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u8a2d\u5b9a\u3059\u308b\u30d1\u30bf\u30fc\u30f3\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Facades\\Schema;\n\nclass AddStatusToOrdersTable extends Migration\n{\n    public function up()\n    {\n        Schema::table('orders', function (Blueprint $table) {\n            \/\/ \u6587\u5b57\u5217\u30ab\u30e9\u30e0\u306b\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u8a2d\u5b9a\n            $table-&gt;string('status')-&gt;default('pending');\n\n            \/\/ \u6570\u5024\u30ab\u30e9\u30e0\u306b\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u8a2d\u5b9a\n            $table-&gt;integer('retry_count')-&gt;default(0);\n\n            \/\/ \u771f\u507d\u5024\u30ab\u30e9\u30e0\u306b\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u8a2d\u5b9a\n            $table-&gt;boolean('is_priority')-&gt;default(false);\n        });\n    }\n\n    public function down()\n    {\n        Schema::table('orders', function (Blueprint $table) {\n            $table-&gt;dropColumn(['status', 'retry_count', 'is_priority']);\n        });\n    }\n}<\/pre>\n\n\n\n<p><strong>\u6ce8\u610f\u70b9<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u306f\u578b\u306b\u5fdc\u3058\u3066\u9069\u5207\u306b\u8a2d\u5b9a<\/li>\n\n\n\n<li>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3078\u306e\u5f71\u97ff\u3092\u8003\u616e<\/li>\n\n\n\n<li>\u65e2\u5b58\u306e\u30d3\u30b8\u30cd\u30b9\u30ed\u30b8\u30c3\u30af\u3068\u306e\u6574\u5408\u6027\u78ba\u8a8d<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-12\">5. \u30e6\u30cb\u30fc\u30af\u5236\u7d04\u4ed8\u304d\u30ab\u30e9\u30e0\u306e\u8ffd\u52a0<\/h3>\n\n\n\n<p>\u4e00\u610f\u6027\u3092\u6301\u3064\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\u3059\u308b\u969b\u306e\u30d1\u30bf\u30fc\u30f3\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Facades\\Schema;\n\nclass AddSlugToArticlesTable extends Migration\n{\n    public function up()\n    {\n        Schema::table('articles', function (Blueprint $table) {\n            \/\/ \u5358\u4e00\u30ab\u30e9\u30e0\u306e\u30e6\u30cb\u30fc\u30af\u5236\u7d04\n            $table-&gt;string('slug')-&gt;unique();\n\n            \/\/ \u8907\u5408\u30e6\u30cb\u30fc\u30af\u5236\u7d04\n            $table-&gt;string('code');\n            $table-&gt;unique(['code', 'user_id']);\n\n            \/\/ \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u4ed8\u304d\u30e6\u30cb\u30fc\u30af\u5236\u7d04\n            $table-&gt;string('sku')-&gt;unique()-&gt;index();\n        });\n    }\n\n    public function down()\n    {\n        Schema::table('articles', function (Blueprint $table) {\n            \/\/ \u30e6\u30cb\u30fc\u30af\u5236\u7d04\u306e\u524a\u9664\n            $table-&gt;dropUnique(['slug']);\n            $table-&gt;dropUnique(['code', 'user_id']);\n\n            \/\/ \u30ab\u30e9\u30e0\u306e\u524a\u9664\n            $table-&gt;dropColumn(['slug', 'code', 'sku']);\n        });\n    }\n}<\/pre>\n\n\n\n<p><strong>\u5b9f\u88c5\u6642\u306e\u6ce8\u610f\u70b9<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u65e2\u5b58\u30c7\u30fc\u30bf\u306e\u4e00\u610f\u6027\u78ba\u8a8d<\/li>\n\n\n\n<li>\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u8ffd\u52a0\u5224\u65ad<\/li>\n\n\n\n<li>\u8907\u5408\u30e6\u30cb\u30fc\u30af\u5236\u7d04\u306e\u691c\u8a0e<\/li>\n<\/ul>\n\n\n\n<p>\u5404\u30d1\u30bf\u30fc\u30f3\u306e\u4f7f\u3044\u5206\u3051\u306e\u30dd\u30a4\u30f3\u30c8\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5358\u7d14\u306a\u6587\u5b57\u5217\u30ab\u30e9\u30e0<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u57fa\u672c\u7684\u306a\u60c5\u5831\u8ffd\u52a0\u6642\u306b\u4f7f\u7528<\/li>\n\n\n\n<li>\u4f4d\u7f6e\u6307\u5b9a\u304c\u5fc5\u8981\u306a\u5834\u5408\u306b\u6d3b\u7528<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u4ed8\u304d<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30c6\u30fc\u30d6\u30eb\u9593\u306e\u95a2\u9023\u3092\u5b9a\u7fa9\u3059\u308b\u969b\u306b\u4f7f\u7528<\/li>\n\n\n\n<li>\u30c7\u30fc\u30bf\u306e\u6574\u5408\u6027\u3092\u4fdd\u8a3c\u3057\u305f\u3044\u5834\u5408<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Nullable\u9805\u76ee<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30aa\u30d7\u30b7\u30e7\u30ca\u30eb\u306a\u60c5\u5831\u3092\u8ffd\u52a0\u3059\u308b\u5834\u5408<\/li>\n\n\n\n<li>\u6bb5\u968e\u7684\u306a\u30c7\u30fc\u30bf\u53ce\u96c6\u3092\u884c\u3046\u5834\u5408<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u4ed8\u304d<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u65e2\u5b58\u30ec\u30b3\u30fc\u30c9\u306b\u5bfe\u3059\u308b\u5024\u306e\u4fdd\u8a3c\u304c\u5fc5\u8981\u306a\u5834\u5408<\/li>\n\n\n\n<li>\u30b7\u30b9\u30c6\u30e0\u306e\u5f8c\u65b9\u4e92\u63db\u6027\u3092\u7dad\u6301\u3059\u308b\u5834\u5408<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30e6\u30cb\u30fc\u30af\u5236\u7d04\u4ed8\u304d<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4e00\u610f\u6027\u304c\u5fc5\u8981\u306a\u30d3\u30b8\u30cd\u30b9\u30eb\u30fc\u30eb\u304c\u3042\u308b\u5834\u5408<\/li>\n\n\n\n<li>\u91cd\u8907\u30c7\u30fc\u30bf\u3092\u9632\u304e\u305f\u3044\u5834\u5408<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u30d1\u30bf\u30fc\u30f3\u3092\u9069\u5207\u306b\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u3088\u308a\u8907\u96d1\u306a\u8981\u4ef6\u306b\u3082\u5bfe\u5fdc\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-13\">\u30ab\u30e9\u30e0\u8ffd\u52a0\u6642\u306e\u30c8\u30e9\u30d6\u30eb\u30b7\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-14\">\u3088\u304f\u3042\u308b\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3068\u305d\u306e\u89e3\u6c7a\u65b9\u6cd5<\/h3>\n\n\n\n<p>\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u5b9f\u884c\u6642\u306b\u3088\u304f\u906d\u9047\u3059\u308b\u30a8\u30e9\u30fc\u3068\u3001\u305d\u306e\u5177\u4f53\u7684\u306a\u89e3\u6c7a\u624b\u9806\u3092\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-15\">1. \u30ab\u30e9\u30e0\u540d\u91cd\u8907\u30a8\u30e9\u30fc<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SQLSTATE[42S21]: Column already exists: 1060 Duplicate column<\/pre>\n\n\n\n<p>\u3053\u306e\u30a8\u30e9\u30fc\u306f\u65e2\u5b58\u306e\u30ab\u30e9\u30e0\u3068\u540c\u3058\u540d\u524d\u306e\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\u3057\u3088\u3046\u3068\u3057\u305f\u969b\u306b\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p><strong>\u89e3\u6c7a\u624b\u9806<\/strong>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ 1. \u30ab\u30e9\u30e0\u306e\u5b58\u5728\u78ba\u8a8d\u3092\u8ffd\u52a0\npublic function up()\n{\n    \/\/ \u30ab\u30e9\u30e0\u304c\u5b58\u5728\u3057\u306a\u3044\u5834\u5408\u306e\u307f\u8ffd\u52a0\n    if (!Schema::hasColumn('users', 'new_column')) {\n        Schema::table('users', function (Blueprint $table) {\n            $table-&gt;string('new_column');\n        });\n    }\n}\n\n\/\/ 2. \u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u6642\u306e\u5bfe\u5fdc\npublic function down()\n{\n    if (Schema::hasColumn('users', 'new_column')) {\n        Schema::table('users', function (Blueprint $table) {\n            $table-&gt;dropColumn('new_column');\n        });\n    }\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-16\">2. \u5916\u90e8\u30ad\u30fc\u5236\u7d04\u30a8\u30e9\u30fc<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SQLSTATE[HY000]: Cannot add foreign key constraint<\/pre>\n\n\n\n<p>\u3053\u306e\u30a8\u30e9\u30fc\u306f\u5916\u90e8\u30ad\u30fc\u306e\u8a2d\u5b9a\u304c\u4e0d\u9069\u5207\u306a\u5834\u5408\u306b\u767a\u751f\u3057\u307e\u3059\u3002\u4e3b\u306a\u539f\u56e0\u306f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u53c2\u7167\u5148\u30c6\u30fc\u30d6\u30eb\u304c\u5b58\u5728\u3057\u306a\u3044<\/li>\n\n\n\n<li>\u30ab\u30e9\u30e0\u306e\u578b\u304c\u4e00\u81f4\u3057\u3066\u3044\u306a\u3044<\/li>\n\n\n\n<li>\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u304c\u5b58\u5728\u3057\u306a\u3044<\/li>\n<\/ul>\n\n\n\n<p><strong>\u89e3\u6c7a\u624b\u9806<\/strong>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public function up()\n{\n    Schema::table('posts', function (Blueprint $table) {\n        \/\/ 1. \u307e\u305a\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\n        $table-&gt;unsignedBigInteger('user_id');\n\n        \/\/ 2. \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u8ffd\u52a0\n        $table-&gt;index('user_id');\n\n        \/\/ 3. \u5916\u90e8\u30ad\u30fc\u5236\u7d04\u3092\u8ffd\u52a0\n        $table-&gt;foreign('user_id')\n              -&gt;references('id')\n              -&gt;on('users')\n              -&gt;onDelete('cascade');\n    });\n}\n\npublic function down()\n{\n    Schema::table('posts', function (Blueprint $table) {\n        \/\/ 1. \u5916\u90e8\u30ad\u30fc\u5236\u7d04\u3092\u524a\u9664\n        $table-&gt;dropForeign(['user_id']);\n        \/\/ 2. \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u524a\u9664\n        $table-&gt;dropIndex(['user_id']);\n        \/\/ 3. \u30ab\u30e9\u30e0\u3092\u524a\u9664\n        $table-&gt;dropColumn('user_id');\n    });\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-17\">\u5927\u898f\u6a21\u30c6\u30fc\u30d6\u30eb\u3067\u306e\u30ab\u30e9\u30e0\u8ffd\u52a0\u6642\u306e\u6ce8\u610f\u70b9<\/h3>\n\n\n\n<p>\u5927\u898f\u6a21\u30c6\u30fc\u30d6\u30eb\u3078\u306e\u30ab\u30e9\u30e0\u8ffd\u52a0\u3067\u306f\u3001\u4ee5\u4e0b\u306e\u70b9\u306b\u7279\u306b\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-18\">1. \u30c6\u30fc\u30d6\u30eb\u30ed\u30c3\u30af\u306e\u6700\u5c0f\u5316<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u975e\u63a8\u5968\u306e\u65b9\u6cd5\uff08\u9577\u6642\u9593\u306e\u30c6\u30fc\u30d6\u30eb\u30ed\u30c3\u30af\uff09\nSchema::table('large_table', function (Blueprint $table) {\n    $table-&gt;string('new_column')-&gt;default('some_value');\n});\n\n\/\/ \u63a8\u5968\u3055\u308c\u308b\u65b9\u6cd5\nSchema::table('large_table', function (Blueprint $table) {\n    \/\/ 1. \u307e\u305aNULL\u8a31\u5bb9\u3067\u8ffd\u52a0\n    $table-&gt;string('new_column')-&gt;nullable();\n});\n\n\/\/ 2. \u30d0\u30c3\u30c1\u51e6\u7406\u3067\u30c7\u30fc\u30bf\u3092\u66f4\u65b0\nUser::chunk(1000, function ($users) {\n    foreach ($users as $user) {\n        $user-&gt;new_column = 'some_value';\n        $user-&gt;save();\n    }\n});\n\n\/\/ 3. \u5fc5\u8981\u306b\u5fdc\u3058\u3066NOT NULL\u5236\u7d04\u3092\u8ffd\u52a0\nSchema::table('large_table', function (Blueprint $table) {\n    $table-&gt;string('new_column')-&gt;nullable(false)-&gt;change();\n});<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-19\">2. \u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u306e\u5236\u5fa1<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u30e1\u30e2\u30ea\u52b9\u7387\u306e\u826f\u3044\u30c7\u30fc\u30bf\u66f4\u65b0\u65b9\u6cd5\nDB::table('large_table')\n    -&gt;select('id')\n    -&gt;orderBy('id')\n    -&gt;chunk(1000, function ($records) {\n        foreach ($records as $record) {\n            DB::table('large_table')\n                -&gt;where('id', $record-&gt;id)\n                -&gt;update(['new_column' =&gt; 'value']);\n        }\n    });<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-20\">\u672c\u756a\u74b0\u5883\u3067\u306e\u30ab\u30e9\u30e0\u8ffd\u52a0\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-21\">1. \u4e8b\u524d\u78ba\u8a8d\u4e8b\u9805<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u5b9f\u884c\u8a08\u753b\u306e\u78ba\u8a8d\nphp artisan migrate --pretend\n\n# \u30c6\u30fc\u30d6\u30eb\u306e\u73fe\u5728\u306e\u72b6\u614b\u78ba\u8a8d\nDESCRIBE users;\n\n# \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u60c5\u5831\u306e\u78ba\u8a8d\nSHOW INDEX FROM users;<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-22\">2. \u5b89\u5168\u306a\u5b9f\u88c5\u30d1\u30bf\u30fc\u30f3<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class AddStatusToOrdersTable extends Migration\n{\n    public function up()\n    {\n        \/\/ 1. \u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u30e2\u30fc\u30c9\u306e\u958b\u59cb\n        Artisan::call('down', [\n            '--message' =&gt; '\u30b7\u30b9\u30c6\u30e0\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u4e2d...',\n            '--retry' =&gt; 60\n        ]);\n\n        try {\n            \/\/ 2. \u30ab\u30e9\u30e0\u8ffd\u52a0\uff08NULL\u8a31\u5bb9\uff09\n            Schema::table('orders', function (Blueprint $table) {\n                $table-&gt;string('status')-&gt;nullable();\n            });\n\n            \/\/ 3. \u65e2\u5b58\u30c7\u30fc\u30bf\u306e\u66f4\u65b0\n            Order::chunk(1000, function ($orders) {\n                foreach ($orders as $order) {\n                    $order-&gt;status = 'pending';\n                    $order-&gt;save();\n                }\n            });\n\n            \/\/ 4. NULL\u5236\u7d04\u306e\u8ffd\u52a0\uff08\u5fc5\u8981\u306a\u5834\u5408\uff09\n            Schema::table('orders', function (Blueprint $table) {\n                $table-&gt;string('status')-&gt;nullable(false)-&gt;change();\n            });\n\n        } finally {\n            \/\/ 5. \u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u30e2\u30fc\u30c9\u306e\u89e3\u9664\n            Artisan::call('up');\n        }\n    }\n\n    public function down()\n    {\n        Schema::table('orders', function (Blueprint $table) {\n            $table-&gt;dropColumn('status');\n        });\n    }\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-23\">3. \u5b9f\u884c\u6642\u306e\u78ba\u8a8d\u9805\u76ee\u30c1\u30a7\u30c3\u30af\u30ea\u30b9\u30c8<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u4e8b\u524d\u78ba\u8a8d<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u306e\u4f5c\u6210<\/li>\n\n\n\n<li>\u30c6\u30fc\u30d6\u30eb\u30b5\u30a4\u30ba\u306e\u78ba\u8a8d<\/li>\n\n\n\n<li>\u95a2\u9023\u3059\u308b\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u78ba\u8a8d<\/li>\n\n\n\n<li>\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u306e\u78ba\u8a8d<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5b9f\u884c\u4e2d\u306e\u76e3\u8996<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30b5\u30fc\u30d0\u30fc\u30ea\u30bd\u30fc\u30b9\u306e\u76e3\u8996<\/li>\n\n\n\n<li>\u30ed\u30c3\u30af\u72b6\u614b\u306e\u78ba\u8a8d<\/li>\n\n\n\n<li>\u30a8\u30e9\u30fc\u30ed\u30b0\u306e\u76e3\u8996<\/li>\n\n\n\n<li>\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u52d5\u4f5c\u78ba\u8a8d<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5b9f\u884c\u5f8c\u306e\u78ba\u8a8d<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30ab\u30e9\u30e0\u306e\u8ffd\u52a0\u78ba\u8a8d<\/li>\n\n\n\n<li>\u30c7\u30fc\u30bf\u306e\u6574\u5408\u6027\u78ba\u8a8d<\/li>\n\n\n\n<li>\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u78ba\u8a8d<\/li>\n\n\n\n<li>\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u52d5\u4f5c\u78ba\u8a8d<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u5bfe\u7b56\u3068\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u3092\u8e0f\u307e\u3048\u308b\u3053\u3068\u3067\u3001\u5927\u898f\u6a21\u306a\u30c6\u30fc\u30d6\u30eb\u3067\u3082\u5b89\u5168\u306b\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u7279\u306b\u672c\u756a\u74b0\u5883\u3067\u306f\u3001\u6bb5\u968e\u7684\u306a\u30a2\u30d7\u30ed\u30fc\u30c1\u3068\u9069\u5207\u306a\u30e2\u30cb\u30bf\u30ea\u30f3\u30b0\u304c\u91cd\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-24\">\u30c1\u30fc\u30e0\u958b\u767a\u306b\u304a\u3051\u308bMigration\u306e\u904b\u7528\u30c6\u30af\u30cb\u30c3\u30af<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-25\">\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u306e\u547d\u540d\u898f\u5247<\/h3>\n\n\n\n<p>\u30c1\u30fc\u30e0\u958b\u767a\u3067\u306f\u3001\u4e00\u8cab\u6027\u306e\u3042\u308b\u547d\u540d\u898f\u5247\u304c\u91cd\u8981\u3067\u3059\u3002\u4ee5\u4e0b\u306e\u898f\u5247\u3092\u63a8\u5968\u3057\u307e\u3059\uff1a<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-26\">1. \u57fa\u672c\u7684\u306a\u547d\u540d\u30d1\u30bf\u30fc\u30f3<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u63a8\u5968\u3055\u308c\u308b\u547d\u540d\u30d1\u30bf\u30fc\u30f3\u4f8b\nYYYY_MM_DD_HHMMSS_action_target_table.php\n\n\/\/ \u5177\u4f53\u4f8b\n2024_02_07_134500_add_status_to_orders_table.php\n2024_02_07_134501_create_product_categories_table.php\n2024_02_07_134502_modify_user_email_column.php<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-27\">2. \u30a2\u30af\u30b7\u30e7\u30f3\u5225\u306e\u547d\u540d\u4f8b<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u30c6\u30fc\u30d6\u30eb\u4f5c\u6210\ncreate_[table_name]_table.php\n\n# \u30ab\u30e9\u30e0\u8ffd\u52a0\nadd_[column_name]_to_[table_name]_table.php\n\n# \u30ab\u30e9\u30e0\u5909\u66f4\nmodify_[column_name]_in_[table_name]_table.php\n\n# \u5916\u90e8\u30ad\u30fc\u8ffd\u52a0\nadd_foreign_key_to_[table_name]_table.php<\/pre>\n\n\n\n<p>\u547d\u540d\u898f\u5247\u306e\u5b9f\u88c5\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u4f5c\u6210\u30b3\u30de\u30f3\u30c9\u4f8b\nphp artisan make:migration add_status_to_orders_table --table=orders\nphp artisan make:migration create_product_categories_table --create=product_categories<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-28\">\u30b3\u30fc\u30c9\u30ec\u30d3\u30e5\u30fc\u3067\u30c1\u30a7\u30c3\u30af\u3059\u3079\u304d\u30dd\u30a4\u30f3\u30c8<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-29\">1. \u30c7\u30fc\u30bf\u6574\u5408\u6027\u306e\u78ba\u8a8d<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class AddStatusToOrdersTable extends Migration\n{\n    public function up()\n    {\n        Schema::table('orders', function (Blueprint $table) {\n            \/\/ \u30ec\u30d3\u30e5\u30fc\u30dd\u30a4\u30f3\u30c81: \u578b\u306e\u9078\u629e\u306f\u9069\u5207\u304b\n            $table-&gt;string('status', 20);  \/\/ \u6587\u5b57\u5217\u9577\u306e\u5236\u9650\n\n            \/\/ \u30ec\u30d3\u30e5\u30fc\u30dd\u30a4\u30f3\u30c82: NULL\u5236\u7d04\u306e\u691c\u8a0e\n            $table-&gt;boolean('is_approved')-&gt;default(false);\n\n            \/\/ \u30ec\u30d3\u30e5\u30fc\u30dd\u30a4\u30f3\u30c83: \u5916\u90e8\u30ad\u30fc\u5236\u7d04\u306e\u6574\u5408\u6027\n            $table-&gt;foreign('user_id')\n                  -&gt;references('id')\n                  -&gt;on('users')\n                  -&gt;onDelete('restrict');  \/\/ \u524a\u9664\u30dd\u30ea\u30b7\u30fc\u306e\u691c\u8a0e\n        });\n    }\n\n    \/\/ \u30ec\u30d3\u30e5\u30fc\u30dd\u30a4\u30f3\u30c84: down()\u30e1\u30bd\u30c3\u30c9\u306e\u5bfe\u79f0\u6027\n    public function down()\n    {\n        Schema::table('orders', function (Blueprint $table) {\n            $table-&gt;dropForeign(['user_id']);\n            $table-&gt;dropColumn(['status', 'is_approved']);\n        });\n    }\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-30\">2. \u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u8003\u616e<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class AddIndexesToOrdersTable extends Migration\n{\n    public function up()\n    {\n        Schema::table('orders', function (Blueprint $table) {\n            \/\/ \u30ec\u30d3\u30e5\u30fc\u30dd\u30a4\u30f3\u30c85: \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u5fc5\u8981\u6027\n            $table-&gt;index('status');\n\n            \/\/ \u30ec\u30d3\u30e5\u30fc\u30dd\u30a4\u30f3\u30c86: \u8907\u5408\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u691c\u8a0e\n            $table-&gt;index(['user_id', 'created_at']);\n        });\n    }\n\n    public function down()\n    {\n        Schema::table('orders', function (Blueprint $table) {\n            $table-&gt;dropIndex(['status']);\n            $table-&gt;dropIndex(['user_id', 'created_at']);\n        });\n    }\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-31\">3. \u30b3\u30fc\u30c9\u30ec\u30d3\u30e5\u30fc\u30c1\u30a7\u30c3\u30af\u30ea\u30b9\u30c8<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30b9\u30ad\u30fc\u30de\u8a2d\u8a08<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30ab\u30e9\u30e0\u540d\u306f\u547d\u540d\u898f\u5247\u306b\u5f93\u3063\u3066\u3044\u308b\u304b<\/li>\n\n\n\n<li>\u30c7\u30fc\u30bf\u578b\u306f\u9069\u5207\u304b<\/li>\n\n\n\n<li>\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306f\u5fc5\u8981\u5341\u5206\u304b<\/li>\n\n\n\n<li>\u5236\u7d04\u306f\u9069\u5207\u306b\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u304b<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5927\u898f\u6a21\u30c7\u30fc\u30bf\u3078\u306e\u5f71\u97ff\u306f\u8003\u616e\u3055\u308c\u3066\u3044\u308b\u304b<\/li>\n\n\n\n<li>\u30ed\u30c3\u30af\u671f\u9593\u306f\u6700\u5c0f\u9650\u304b<\/li>\n\n\n\n<li>\u9069\u5207\u306a\u30d0\u30c3\u30c1\u51e6\u7406\u304c\u5b9f\u88c5\u3055\u308c\u3066\u3044\u308b\u304b<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u904b\u7528\u9762<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u306f\u9069\u5207\u306b\u5b9f\u88c5\u3055\u308c\u3066\u3044\u308b\u304b<\/li>\n\n\n\n<li>\u5b9f\u884c\u9806\u5e8f\u306f\u9069\u5207\u304b<\/li>\n\n\n\n<li>\u30c7\u30d7\u30ed\u30a4\u624b\u9806\u306f\u660e\u78ba\u304b<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-32\">\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u5c65\u6b74\u306e\u7ba1\u7406\u65b9\u6cd5<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-33\">1. \u5c65\u6b74\u30c6\u30fc\u30d6\u30eb\u306e\u6d3b\u7528<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u5c65\u6b74\u306e\u78ba\u8a8d\nphp artisan migrate:status\n\n# \u5c65\u6b74\u306e\u30ea\u30bb\u30c3\u30c8\nphp artisan migrate:reset\n\n# \u7279\u5b9a\u306e\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u307e\u3067\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\nphp artisan migrate:rollback --step=2<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-34\">2. \u30d0\u30fc\u30b8\u30e7\u30f3\u7ba1\u7406\u3067\u306e\u904b\u7528\u4f8b<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u30b7\u30fc\u30c9\u30c7\u30fc\u30bf\u3092\u542b\u3080\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u4f8b\nclass CreateProductCategoriesTable extends Migration\n{\n    public function up()\n    {\n        Schema::create('product_categories', function (Blueprint $table) {\n            $table-&gt;id();\n            $table-&gt;string('name');\n            $table-&gt;string('slug')-&gt;unique();\n            $table-&gt;timestamps();\n        });\n\n        \/\/ \u521d\u671f\u30c7\u30fc\u30bf\u306e\u6295\u5165\n        $categories = [\n            ['name' =&gt; '\u96fb\u5316\u88fd\u54c1', 'slug' =&gt; 'electronics'],\n            ['name' =&gt; '\u66f8\u7c4d', 'slug' =&gt; 'books'],\n            ['name' =&gt; '\u8863\u985e', 'slug' =&gt; 'clothing']\n        ];\n\n        DB::table('product_categories')-&gt;insert($categories);\n    }\n\n    public function down()\n    {\n        Schema::dropIfExists('product_categories');\n    }\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i-35\">3. \u30c1\u30fc\u30e0\u958b\u767a\u3067\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30d6\u30e9\u30f3\u30c1\u6226\u7565<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   # \u6a5f\u80fd\u30d6\u30e9\u30f3\u30c1\u3067\u306e\u4f5c\u696d\n   git checkout -b feature\/add-order-status\n\n   # \u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210\n   php artisan make:migration add_status_to_orders_table\n\n   # \u5909\u66f4\u3092\u30b3\u30df\u30c3\u30c8\n   git add database\/migrations\/*\n   git commit -m \"feat: add status column to orders table\"<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u30b3\u30f3\u30d5\u30ea\u30af\u30c8\u5bfe\u7b56<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   \/\/ \u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7\u306e\u8abf\u6574\n   \/\/ 2024_02_07_134500_add_status_to_orders_table.php\n   \/\/ 2024_02_07_134501_add_payment_info_to_orders_table.php\n\n   \/\/ \u4f9d\u5b58\u95a2\u4fc2\u304c\u3042\u308b\u5834\u5408\u306f\u660e\u793a\u7684\u306b\u30b3\u30e1\u30f3\u30c8\u3067\u8a18\u8f09\n   \/**\n    * @depends 2024_02_07_134500_add_status_to_orders_table\n    *\/\n    class AddPaymentInfoToOrdersTable extends Migration<\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>\u30c7\u30d7\u30ed\u30a4\u30e1\u30f3\u30c8\u30d5\u30ed\u30fc<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">   # \u30b9\u30c6\u30fc\u30b8\u30f3\u30b0\u74b0\u5883\u3067\u306e\u78ba\u8a8d\n   php artisan migrate --pretend\n   php artisan migrate\n\n   # \u672c\u756a\u74b0\u5883\u3067\u306e\u30c7\u30d7\u30ed\u30a4\n   php artisan migrate --force<\/pre>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u904b\u7528\u30c6\u30af\u30cb\u30c3\u30af\u3092\u9069\u5207\u306b\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u30c1\u30fc\u30e0\u958b\u767a\u306b\u304a\u3051\u308b\u52b9\u7387\u7684\u306a\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u7ba1\u7406\u304c\u5b9f\u73fe\u3067\u304d\u307e\u3059\u3002\u7279\u306b\u3001\u547d\u540d\u898f\u5247\u306e\u7d71\u4e00\u3068\u30b3\u30fc\u30c9\u30ec\u30d3\u30e5\u30fc\u306e\u5fb9\u5e95\u306f\u3001\u9577\u671f\u7684\u306a\u4fdd\u5b88\u6027\u306e\u5411\u4e0a\u306b\u5927\u304d\u304f\u8ca2\u732e\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-36\">\u30ab\u30e9\u30e0\u8ffd\u52a0\u306e\u5fdc\u7528\u30c6\u30af\u30cb\u30c3\u30af<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-37\">\u8907\u6570\u30ab\u30e9\u30e0\u306e\u4e00\u62ec\u8ffd\u52a0\u65b9\u6cd5<\/h3>\n\n\n\n<p>\u5927\u898f\u6a21\u306a\u30c6\u30fc\u30d6\u30eb\u6539\u4fee\u3067\u3088\u304f\u5fc5\u8981\u3068\u306a\u308b\u3001\u8907\u6570\u30ab\u30e9\u30e0\u306e\u4e00\u62ec\u8ffd\u52a0\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class AddUserProfileFieldsToUsersTable extends Migration\n{\n    public function up()\n    {\n        \/\/ \u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u3067\u8907\u6570\u306e\u30ab\u30e9\u30e0\u8ffd\u52a0\u3092\u307e\u3068\u3081\u308b\n        DB::transaction(function () {\n            Schema::table('users', function (Blueprint $table) {\n                \/\/ \u30d7\u30ed\u30d5\u30a3\u30fc\u30eb\u95a2\u9023\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u4e00\u62ec\u8ffd\u52a0\n                $table-&gt;string('nickname', 50)\n                      -&gt;nullable()\n                      -&gt;after('name')\n                      -&gt;comment('\u30e6\u30fc\u30b6\u30fc\u306e\u30cb\u30c3\u30af\u30cd\u30fc\u30e0');\n\n                $table-&gt;text('introduction')\n                      -&gt;nullable()\n                      -&gt;after('nickname')\n                      -&gt;comment('\u81ea\u5df1\u7d39\u4ecb\u6587');\n\n                $table-&gt;string('location', 100)\n                      -&gt;nullable()\n                      -&gt;after('introduction')\n                      -&gt;comment('\u5c45\u4f4f\u5730');\n\n                \/\/ \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3082\u540c\u6642\u306b\u8ffd\u52a0\n                $table-&gt;index('nickname');\n            });\n\n            \/\/ \u65e2\u5b58\u30e6\u30fc\u30b6\u30fc\u306e\u30cb\u30c3\u30af\u30cd\u30fc\u30e0\u3092\u521d\u671f\u8a2d\u5b9a\n            DB::table('users')-&gt;whereNull('nickname')\n                -&gt;lazyById()\n                -&gt;each(function ($user) {\n                    DB::table('users')\n                        -&gt;where('id', $user-&gt;id)\n                        -&gt;update(['nickname' =&gt; 'user_' . $user-&gt;id]);\n                });\n        });\n    }\n\n    public function down()\n    {\n        Schema::table('users', function (Blueprint $table) {\n            \/\/ \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u524a\u9664\n            $table-&gt;dropIndex(['nickname']);\n\n            \/\/ \u30ab\u30e9\u30e0\u306e\u4e00\u62ec\u524a\u9664\n            $table-&gt;dropColumn([\n                'nickname',\n                'introduction',\n                'location'\n            ]);\n        });\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-38\">\u6761\u4ef6\u4ed8\u304d\u3067\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\u3059\u308b\u65b9\u6cd5<\/h3>\n\n\n\n<p>\u30b7\u30b9\u30c6\u30e0\u8981\u4ef6\u3084\u74b0\u5883\u306b\u5fdc\u3058\u3066\u3001\u6761\u4ef6\u4ed8\u304d\u3067\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\u3059\u308b\u5b9f\u88c5\u30d1\u30bf\u30fc\u30f3\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class AddAuditFieldsToOrdersTable extends Migration\n{\n    public function up()\n    {\n        \/\/ \u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3084\u30b7\u30b9\u30c6\u30e0\u8981\u4ef6\u306b\u57fa\u3065\u304f\u6761\u4ef6\u5206\u5c90\n        if (config('app.audit_enabled', false)) {\n            Schema::table('orders', function (Blueprint $table) {\n                \/\/ \u76e3\u67fb\u7528\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u8ffd\u52a0\n                $table-&gt;string('created_by')\n                      -&gt;nullable()\n                      -&gt;comment('\u4f5c\u6210\u8005\u306e\u30e6\u30fc\u30b6\u30fcID');\n\n                $table-&gt;string('updated_by')\n                      -&gt;nullable()\n                      -&gt;comment('\u6700\u7d42\u66f4\u65b0\u8005\u306e\u30e6\u30fc\u30b6\u30fcID');\n\n                $table-&gt;ipAddress('created_from')\n                      -&gt;nullable()\n                      -&gt;comment('\u4f5c\u6210\u5143IP\u30a2\u30c9\u30ec\u30b9');\n            });\n\n            \/\/ \u65e2\u5b58\u30ec\u30b3\u30fc\u30c9\u306e\u4f5c\u6210\u8005\u60c5\u5831\u3092\u8a2d\u5b9a\n            $defaultUser = config('app.admin_user_id');\n            DB::table('orders')\n                -&gt;whereNull('created_by')\n                -&gt;lazyById()\n                -&gt;each(function ($order) use ($defaultUser) {\n                    DB::table('orders')\n                        -&gt;where('id', $order-&gt;id)\n                        -&gt;update([\n                            'created_by' =&gt; $defaultUser,\n                            'updated_by' =&gt; $defaultUser\n                        ]);\n                });\n        }\n    }\n\n    public function down()\n    {\n        if (config('app.audit_enabled', false)) {\n            Schema::table('orders', function (Blueprint $table) {\n                $table-&gt;dropColumn([\n                    'created_by',\n                    'updated_by',\n                    'created_from'\n                ]);\n            });\n        }\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-39\">\u30ab\u30e9\u30e0\u8ffd\u52a0\u3068\u540c\u6642\u306b\u30c7\u30fc\u30bf\u3092\u8a2d\u5b9a\u3059\u308b\u65b9\u6cd5<\/h3>\n\n\n\n<p>\u30ab\u30e9\u30e0\u8ffd\u52a0\u6642\u306b\u65e2\u5b58\u30c7\u30fc\u30bf\u304b\u3089\u65b0\u3057\u3044\u5024\u3092\u5c0e\u51fa\u30fb\u8a2d\u5b9a\u3059\u308b\u5b9f\u88c5\u30d1\u30bf\u30fc\u30f3\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class AddDisplayNameToUsersTable extends Migration\n{\n    public function up()\n    {\n        DB::transaction(function () {\n            \/\/ 1. \u65b0\u3057\u3044\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\uff08\u4e00\u6642\u7684\u306bNULL\u8a31\u5bb9\uff09\n            Schema::table('users', function (Blueprint $table) {\n                $table-&gt;string('display_name')\n                      -&gt;nullable()\n                      -&gt;after('name')\n                      -&gt;comment('\u8868\u793a\u540d');\n            });\n\n            \/\/ 2. \u65e2\u5b58\u30c7\u30fc\u30bf\u304b\u3089\u8868\u793a\u540d\u3092\u751f\u6210\n            DB::table('users')\n                -&gt;whereNull('display_name')\n                -&gt;lazyById()\n                -&gt;each(function ($user) {\n                    \/\/ \u8868\u793a\u540d\u306e\u751f\u6210\u30ed\u30b8\u30c3\u30af\n                    $displayName = $this-&gt;generateDisplayName($user);\n\n                    DB::table('users')\n                        -&gt;where('id', $user-&gt;id)\n                        -&gt;update(['display_name' =&gt; $displayName]);\n                });\n\n            \/\/ 3. NULL\u5236\u7d04\u3092\u8ffd\u52a0\n            Schema::table('users', function (Blueprint $table) {\n                $table-&gt;string('display_name')\n                      -&gt;nullable(false)\n                      -&gt;change();\n            });\n        });\n    }\n\n    public function down()\n    {\n        Schema::table('users', function (Blueprint $table) {\n            $table-&gt;dropColumn('display_name');\n        });\n    }\n\n    \/**\n     * \u30e6\u30fc\u30b6\u30fc\u306e\u8868\u793a\u540d\u3092\u751f\u6210\n     *\/\n    private function generateDisplayName($user): string\n    {\n        \/\/ \u540d\u524d\u304c\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u306f\u305d\u308c\u3092\u4f7f\u7528\n        if (!empty($user-&gt;name)) {\n            return $user-&gt;name;\n        }\n\n        \/\/ \u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u306e\u30ed\u30fc\u30ab\u30eb\u90e8\u3092\u4f7f\u7528\n        $localPart = explode('@', $user-&gt;email)[0];\n        return ucfirst($localPart);\n    }\n}<\/pre>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u5fdc\u7528\u30c6\u30af\u30cb\u30c3\u30af\u3092\u4f7f\u7528\u3059\u308b\u969b\u306e\u91cd\u8981\u306a\u30dd\u30a4\u30f3\u30c8\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3078\u306e\u914d\u616e<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>lazyById()<\/code>\u3092\u4f7f\u7528\u3057\u305f\u52b9\u7387\u7684\u306a\u30c7\u30fc\u30bf\u51e6\u7406<\/li>\n\n\n\n<li>\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u306e\u9069\u5207\u306a\u4f7f\u7528<\/li>\n\n\n\n<li>\u30d0\u30c3\u30c1\u51e6\u7406\u3067\u306e\u66f4\u65b0<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30c7\u30fc\u30bf\u6574\u5408\u6027\u306e\u78ba\u4fdd<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4e00\u6642\u7684\u306aNULL\u8a31\u5bb9\u3068\u6bb5\u968e\u7684\u306a\u5236\u7d04\u8ffd\u52a0<\/li>\n\n\n\n<li>\u9069\u5207\u306a\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u306e\u8a2d\u5b9a<\/li>\n\n\n\n<li>\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u306e\u5b9f\u88c5<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u6027\u306e\u5411\u4e0a<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30b3\u30e1\u30f3\u30c8\u306b\u3088\u308b\u30ab\u30e9\u30e0\u306e\u8aac\u660e\u8ffd\u52a0<\/li>\n\n\n\n<li>\u6761\u4ef6\u5206\u5c90\u306e\u660e\u78ba\u306a\u8a18\u8ff0<\/li>\n\n\n\n<li>\u30d7\u30e9\u30a4\u30d9\u30fc\u30c8\u30e1\u30bd\u30c3\u30c9\u3067\u306e\u30ed\u30b8\u30c3\u30af\u5206\u5272<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u904b\u7528\u4e0a\u306e\u6ce8\u610f\u70b9<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u5b9f\u884c\u524d\u306e\u30d0\u30c3\u30af\u30a2\u30c3\u30d7<\/li>\n\n\n\n<li>\u5b9f\u884c\u8a08\u753b\u306e\u78ba\u8a8d\uff08\u2013pretend\u30aa\u30d7\u30b7\u30e7\u30f3\u306e\u4f7f\u7528\uff09<\/li>\n\n\n\n<li>\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u306e\u52d5\u4f5c\u78ba\u8a8d<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u30c6\u30af\u30cb\u30c3\u30af\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u3088\u308a\u67d4\u8edf\u3067\u5b89\u5168\u306a\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u5909\u66f4\u7ba1\u7406\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002\u7279\u306b\u5927\u898f\u6a21\u306a\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3067\u306f\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3068\u30c7\u30fc\u30bf\u6574\u5408\u6027\u306e\u4e21\u9762\u306b\u6ce8\u610f\u3092\u6255\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Warning: Undefined array key &#8220;is_admin&#8221; in \/home\/xs392991\/dexall.co.jp\/public_html\/articles\/wp-content\/themes\/ &#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":{"0":"post-2655","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-uncategorized","7":"nothumb"},"_links":{"self":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts\/2655","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2655"}],"version-history":[{"count":1,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts\/2655\/revisions"}],"predecessor-version":[{"id":2656,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts\/2655\/revisions\/2656"}],"wp:attachment":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2655"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}