Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Schema::dropIfExists()在migrate:rollback时删除了数据库中的所有表_Php_Mysql_Laravel_Laravel 5_Migration - Fatal编程技术网

Php Schema::dropIfExists()在migrate:rollback时删除了数据库中的所有表

Php Schema::dropIfExists()在migrate:rollback时删除了数据库中的所有表,php,mysql,laravel,laravel-5,migration,Php,Mysql,Laravel,Laravel 5,Migration,我在命令行上运行了php artisan migrate:rollback,因此迁移删除了数据库中的所有表 只创建了一个迁移,但在数据库中使用了其他表 laravel的文件中说: 要删除现有表,可以使用drop或dropIfExists方法 迁移代码上的函数down()是默认值,如下所示: public function up() { Schema::create('products', function (Blueprint $table) {

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

只创建了一个迁移,但在数据库中使用了其他表

laravel的文件中说: 要删除现有表,可以使用drop或dropIfExists方法

迁移代码上的函数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');
    }
}

我不认为
模式::dropIfExists('products')
工作正常。在这种情况下,这是一个bug吗?还是我(和laravel文档)的错误?

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

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


我知道这篇文章已经有一年多的历史了,但这可能会帮助其他有这个问题并正在寻找解决方案的人。我猜这里发生的事情是,如果您运行
php artisan migrate:rollback
它将回滚上一批中的所有迁移。换句话说,它将在同一批中的所有迁移中运行所有
down()
函数。因此,如果在恢复更改(删除创建的表)的迁移中执行了
down()
函数,那么这些迁移也将运行


为了防止出现这种情况,可以添加
--step
参数来指示应该回滚多少次迁移,如下所示:
php-artisan-migrate:rollback--step=1
。然后,将只回滚最后一次迁移。

还有哪些表?如果数据库中有其他表,也应该为它们进行迁移,在这些迁移中,应该有一个调用
Schema::drop()
(或
dropIfExists()
)的
down()
函数。可能需要更多的信息。我不能说我听说过这样的事情。是一个现有的旧版本数据库。我甚至还没有创建其他迁移,因为数据库中有100多个表,但在我的项目中没有其他迁移