laravel 5.4 中使用migrate
Posted 侠岚之弋痕夕
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了laravel 5.4 中使用migrate相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章
Laravel 5.4 migrate时报错: Specified key was too long error
Laravel 5.4 migrate时报错: Specified key was too long error
Laravel 5.4 migrate报错:Syntax error or access violation: 1071 Specified key was too long; max key len