先生成一个新的迁移文件

php artisan make:migration add_users_table

新的迁移文件中写入要添加的字段

// 运行迁移时会被调用
public function up()
{
    Schema::table('users',function (Blueprint $table) {
        $table->string('avatar')->after('name')->default('');
    });
}

// 回滚迁移时会被调用  如果不回滚这里可以不用改 用默认的就可以
public function down()
{
    Schema::table('users', function (Blueprint $table) {
        $table->dropColumn('avatar');
    });
}

我们将 avatar 字段放在 name 字段后面。而修改表和创建表的区别就是 create 方法改成 table 方法

最后执行

php artisan migrate

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-10
  • 2022-12-23
  • 2021-11-21
  • 2021-06-18
  • 2022-01-02
猜你喜欢
  • 2021-11-11
  • 2021-11-11
  • 2022-12-23
  • 2022-12-23
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案