laravel migrate增加、修改、刪除字段

生成migration文件

php artisan make:migration alter_xxx_table

修改migration文件

/**
 * Run the migrations.
 *
 * @return void
 */    
public function up()
{
	Schema::table('xxx', function (Blueprint $table) {
		$table->string('a', 1000); //增加
		$table->string('b', 100)->nullable()->change(); //修改
		$table->renameColumn('c', 'd'); //重命名
		$table->dropColumn(['e', 'f', 'g']);//刪除
	});
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
	Schema::table('xxx', function (Blueprint $table) {
		$table->drop_column('a'); //增加
		$table->string('b', 100)->change(); //修改
		$table->renameColumn('d', 'c'); //重命名
		$table->string('e', 1000); //刪除
		$table->string('f', 1000); //刪除
		$table->string('g', 1000); //刪除
	});
}

 

執行命令

php artisan migrate 

 

撤回命令

php artisan migrate:rollback --step=n(n爲撤回步數)

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章