1. 创建表结构
a.
命令: php artisan make:migration create_posts_table
2.生产文件
<?php use IlluminateSupportFacadesSchema; use IlluminateDatabaseSchemaBlueprint; use IlluminateDatabaseMigrationsMigration; 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.修改文件:appProvidersAppServiceProvider.php
b. use IlluminateSupportFacadesSchema;
c. Schema::defaultStringcLength(191);