Lumen框架 之数据库迁移
  RHipNrtaSLhH 2023年11月18日 69 0

一、基本操作

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



【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月18日 0

暂无评论

推荐阅读
  NT5NRjELxLp1   2024年04月29日   70   0   0 PHP
  iALoCqVB8AGc   2023年12月25日   36   0   0 PHP
  yThMa20bw7iV   2024年02月19日   71   0   0 PHP
  iyViKl6W0XQr   2024年05月17日   55   0   0 PHP
  NT5NRjELxLp1   2024年03月14日   83   0   0 PHP
RHipNrtaSLhH