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

658次阅读
没有评论

生成migration文件

 php artisan make:migration alter_xxx_table 

修改migration文件

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为撤回步数) 

正文完
可以使用微信扫码关注公众号(ID:xzluomor)
post-qrcode
 
评论(没有评论)