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

laravel 5.4 中使用migrate

时间:2018-11-03 19:21:35      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:code   rev   分享图片   public   mina   属性   length   分享   php   

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

标签:code   rev   分享图片   public   mina   属性   length   分享   php   

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

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