如何在没有 migrate:fresh 的情况下将已迁移的迁移设置为 Laravel 中的已迁移迁移?

How can i set already migrated migrations as a migrated migrations in Laravel without migrate:fresh?

我的数据库中有 20 个 table。我想将一个新的迁移到数据库中。 但是我得到了错误:

Base table or view already exists: 1050 Table 'house_statuses' already exists.

这个 table 已经在数据库中了,但是每次我想迁移一些新东西时,我都会得到这个,而这个迁移已经在早些时候迁移了。

我看到了一些解决方案,比如 Migrate:fresh, 但我不想删除我在数据库中的记录,因为设置记录需要做很多工作

按照以下步骤操作:

  1. 找到您提到的文件名来创建这个table。

  2. 复制文件名

  3. 将文件名插入迁移 table。

可能对你有帮助。

如果您想在 table 中插入更多列,您应该使用 Schema::table,例如:

假设您的 users table 中还需要一列,您可以简单地这样做:

使用命令:

php artisan make:migration add_age_to_users_table --table=users
Schema::table('users', function (Blueprint $table) {
    $table->integer('age');
});

然后使用:

php artisan migrate

这样您的 users table 将更新为新列 age

每次您想在数据库中进行更改时,您应该创建一个新的迁移而不是编辑最后一个