首先执行命令 php artisan make:migration create_table_testtable
然后在database/migrations中找到文件
内容为
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
class CreateTableTesttable extends Migration
{
public function up()
{
Schema::create('table_testtable', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 20);
// $table->timestamps();
$table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
$table->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP'));
});
}
public function down()
{
Schema::dropIfExists('table_testtable');
}
}
然后执行php artisan migrate即可
如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术
转载请注明:laravel使用迁移创建数据库表 出自老鄢博客 | 欢迎分享