php - Schema::dropIfExists() 在迁移时删除了数据库中的所有表:回滚

标签 php mysql laravel laravel-5 migration

我在命令行上运行了php artisan migrate:rollback,因此迁移删除了数据库中的所有表。

仅创建了一个迁移,但已使用的数据库中有其他表。

laravel documentation说:

To drop an existing table, you may use the drop or dropIfExists methods.

迁移代码中的函数 down() 是默认的,如下所示:

public function up()
    {
        Schema::create('products', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('image')->unsigned()->nullable();
            $table->string('name', 64);
            $table->string('slug', 64)->unique();
            $table->integer('price')->unsigned();
            $table->timestamps();
        });
    }

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

我认为 Schema::dropIfExists('products') 在这种情况下无法正常工作,这是一个错误吗?或者我的(和 laravel 文档)错误?

最佳答案

回滚,回滚上一批的每个迁移。

如果您的所有迁移都在同一批处理中,那么它将回滚所有迁移。因此您的所有表都将从数据库中删除。

enter image description here

关于php - Schema::dropIfExists() 在迁移时删除了数据库中的所有表:回滚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56367482/

相关文章:

php - 这个 PHP 脚本有什么问题?

php - PHP 中的单词出现次数 - 缩放和优化

php - 从自定义分类生成 WordPress 菜单

php - 查询数据库中的倒计时器

php - mysql 和 php 中按日期范围分组

mysql - 如何从 DO Droplet Ubuntu 18.04 连接到 DO 托管 MySQL 8?

php - PHP 中的 MySQL 结果数组

php - CodeIgniter Active Record 多个 WHERE 子句

laravel - 使用作者姓名存储数据 - laravel 5.2

mysql - 根据当前选择添加额外的商店过滤器