laravel版本迁移

1、如果不知道命令怎么写的话,可以使用php artisan

2、创建版本迁移文件:php artisan make:migration 文件的名称(create_users_table)建议这种命名规范,users为表名+s

3、该文件存在app/database/migrations中,进入该文件,有两个方法,up()用于运行,down()用于回滚

4、

 public function up()
    {
        Schema::create('posts', function (Blueprint $table) {//create为创建表,table为更新表
            $table->increments('id');
            $table->string('title','100')->default("");
            $table->text('content');
            $table->integer('user_id')->default(0);//integer代表int类型
            $table->timestamps();
        });
    }
public function down()
{
Schema::dropIfExists('posts');
}

5、运行文件:php artisan migrate

6、如有以下报错:

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too lo  
  ng; max key length is 1000 bytes  
//可以在app/providers/appserviceprovider.php中的boot()方法中写入
Schema::defaultStringLength(191);

猜你喜欢

转载自www.cnblogs.com/hanmengya/p/10855875.html