小白兔晒黑了

导航

 

1 添加自动加载

\composer.json

添加    "database/migrations",

  "autoload": {
        "classmap": [
            "database/seeds",
            "database/migrations",
            "database/factories"
        ],

运行

composer dump-autoload

2 安装依赖

composer require doctrine/dbal

3 添加修改数据表结构的迁移

3.1 新增字段

 php artisan make:migration add_字段名_to_表名_table --table=表名

 php artisan make:migration add_api_token_to_users_table --table=users

生成文件 \database\migrations\2021_04_21_161607_add_api_token_to_users_table.php

修改其中的up方法

    public function up()
    {
        Schema::table('users',function (Blueprint $table){
            $table->string('api_token',80)
              ->after('password')
              ->unique()
              ->nullable()
              ->default(null);
        });
    }

 

3.2 其他修改数据表的操作:

https://learnku.com/docs/laravel/7.x/migrations/7496#55682c

4 执行迁移

php artisan tinker
(new AddApiTokenToUsersTable)->up();

字段已添加成功

 

posted on 2021-04-22 01:27  小白兔晒黑了  阅读(117)  评论(0编辑  收藏  举报