首页 > 其他 > 详细

laravel 5.4 中使用migrate

时间:2018-11-03 18:50:25      阅读:136      评论:0      收藏:0      [点我收藏+]

1. 创建表结构

a.技术分享图片

命令: php artisan make:migration create_posts_table

2.生产文件

<?php

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

class CreatePostsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create(‘posts‘, function (Blueprint $table) {
            $table->increments(‘id‘);
            $table->string(‘title‘, 120)->default("");
            $table->text(‘content‘);
            $table->integer(‘user_id‘)->default(0);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists(‘posts‘);
    }
}

3. 当自定义完表属性后,生成表

命令: php artisan migrate

 

注意:如果是laravel5.4 会报错

技术分享图片

解决方案:

a.修改文件:app\Providers\AppServiceProvider.php

b.   use Illuminate\Support\Facades\Schema;

c.      Schema::defaultStringcLength(191);

技术分享图片

 

laravel 5.4 中使用migrate

原文:https://www.cnblogs.com/wuheng1991/p/9901513.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!