composer require doctrine/dbal
add_columns_articles_table は任意の命名でOKですが「作業内容_テーブル名_table」としておくとテーブル作成時のファイルと命名が揃います
php artisan make:migration add_columns_articles_table --table=articles
例:「articles」テーブルに以下のカラムを追加します
・「status_id」カラムの後ろにint型の「recruit_flg」を追加します
・「recruit_flg」カラムの後ろにint型の「recruit_date」を追加します
public function up()
{
Schema::table('articles', function (Blueprint $table) {
$table->integer('recruit_flg')->default(0)->after('status_id'); // この行を追加
$table->dateTime('recruit_date')->nullable()->after('recruit_flg'); // この行を追加
});
}
注意:SQLiteでは任意の位置にカラム追加が出来ないようです
回避策 : https://goo.gl/a2atCx
public function down()
{
Schema::table('articles', function (Blueprint $table) {
$table->dropColumn(['recruit_date','recruit_flg']);
});
}
php artisan migrate
php artisan migrate:rollback
以上で、既存のデータベースのデータを削除することなく、カラムを追加できます。