Lumen框架 之数据库迁移

一、基本操作

1、/database/migrations/ 目录下生成一个php文件,这个文件主要包括两个函数,在up()函数中根据你的需求定义数据库字段

php artisan make:migration create_users_table --create=users
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('username', 32);
            $table->string('password', 32);
            $table->string('email')->nullable();
            $table->string('salt', 6);
            $table->string('api_token')->nullable();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

2、执行命令,创建数据库

php artisan migrate

二、文档

https://learnku.com/docs/laravel/6.x/migrations/5173

posted @ 2023-10-13 09:59  样子2018  阅读(33)  评论(0编辑  收藏  举报