laravel中使用命令生成数据库表

配置.env数据库连接配置
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=database_name DB_USERNAME=username DB_PASSWORD=password 在项目路的根目录下输入下面的命令 php artisan make:migration create_posts_table 会在databse/migrations目录下生成一个php文件
<?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'); $table->string('body'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('posts'); } } 在项目路的根目录下输入下面的命令 php artisan make:migrate 会在数据中自动生成一张posts表