【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、

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM