码迷,mamicode.com
首页 > 其他好文 > 详细

laravel版本迁移

时间:2019-05-13 12:35:05      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:creat   pps   类型   sts   div   ecif   sch   laravel   key   

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);

laravel版本迁移

标签:creat   pps   类型   sts   div   ecif   sch   laravel   key   

原文地址:https://www.cnblogs.com/hanmengya/p/10855875.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!