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);
原文地址:https://www.cnblogs.com/wuheng1991/p/9901513.html
时间: 2024-11-08 23:50:43