laravel 5.4 中使用migrate
阿新 • • 發佈:2018-11-03
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);