Laravel migrationの作り方・更新

テーブルを作成・追加
<code>
Schema::create('hoges', function (Blueprint $table){
$table->string('hogehoge')->nullable();
$table->string('hugahuga');
}
</code>
テーブルを更新
changeメソッドは存在するカラムを新しいタイプへ変更するか、カラムの属性を変えます。
<code>Schema::table('hoges', function (Blueprint $table) {
$table->string('name', 50)->nullable()->change();
});
</code>
テーブルを削除
<code>Schema::table('hoges', function (Blueprint $table) {
Schema::drop('posts');//テーブルを削除。ただしテーブルがない場合エラーになる
Schema::dropIfExists('posts');//テーブルがあれば削除
});
</code>
カラムを削除
<code>Schema::table('hoges', function (Blueprint $table) {
$table->dropColumn('hogehoge');
});
</code>







LEAVE A REPLY