Laravel Migrate

本文详细介绍如何使用Laravel的Artisan命令创建和执行数据库迁移,包括添加字段和回滚操作。通过实例展示了如何合并两个用户表的数据结构,适用于需要进行数据库结构调整的Laravel开发者。
Lravel Migrate

创建一个migrate

php artisan make:migration merge_ecshop_and_xingqiu_user_table --table=ecs_users

编写数据库迁移语句

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class MergeEcshopAndXingqiuUserTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->tinyInteger('grade_id')->default(0);
            $table->dateTime('grade_updtime')->nullable();
            $table->integer('grade_ref_objid')->nullable();
            $table->integer('lvl1')->default(1);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
          $table->dropColumn('grade_id');
          $table->dropColumn('grade_updtime');
          $table->dropColumn('grade_ref_objid');
          $table->dropColumn('lvl1');
        });
    }
}

执行迁移

php artisan migrate

回滚
此命令将回滚最后一次“迁移”的操作

php artisan migrate:rollback
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值