【laravel5.4】迁移文件的生成、修改、删除

 

建议直接去官方文档查看: https://laravel-china.org/docs/laravel/5.4/migrations#creating-columns

 

1、生成迁移:

主要方式:1、创建空的迁移文件,不指定具体表:php artisan make:migration create_users_table

public function up()
    {
        //
    }

          2、再次创建修改类型的迁移文件(原有新建文件不动),指向已经存在的表,方法体是:php artisan make:migration update_votes_to_users_table --table=testaa

 

public function up()
    {
        Schema::table('testaa', function (Blueprint $table) {    //分别向原来的表插入新的字段

      $table->integer('scope')->nullable()->comment('得分');  
      $table->decimal('money',9,2)->comment('金额');

        });
    }

      3、创建迁移文件的同时,创建数据表:php artisan make:migration create_users_table --create=users

public function up()
    {
        Schema::create('userss', function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
        });
    }

 

2、执行迁移:   

 

 3、还原迁移:

4、 

5、 

6、修改已存在的数据表:

 

7、

 

posted @ 2018-04-15 17:39  PHP急先锋  阅读(5366)  评论(0编辑  收藏  举报