拉维公司;MongoDB:无法使用migrate:fresh删除现有集合
我无法通过运行migrate:fresh删除MongoDB集合。该项目位于Laravel 5.7上,我们使用的是拉维公司;MongoDB:无法使用migrate:fresh删除现有集合,mongodb,laravel,laravel-5.7,laravel-migrations,jenssegers-mongodb,Mongodb,Laravel,Laravel 5.7,Laravel Migrations,Jenssegers Mongodb,我无法通过运行migrate:fresh删除MongoDB集合。该项目位于Laravel 5.7上,我们使用的是Jenssers/Laravel mongodb。当我尝试运行migrate:fresh时,出现了一个错误 MongoDB\Driver\Exception\CommandException:集合“project.drivers”已存在 如果手动删除集合并运行migrate:fresh,则会再次创建集合。这让人困惑,好像可以使用Schema::connection('mongodb')
Jenssers/Laravel mongodb
。当我尝试运行migrate:fresh时,出现了一个错误
MongoDB\Driver\Exception\CommandException:集合“project.drivers”已存在
如果手动删除集合并运行migrate:fresh,则会再次创建集合。这让人困惑,好像可以使用Schema::connection('mongodb')->create('drivers',…
我不确定为什么在运行Schema::connection('mongodb')->drop('drivers');
下面是我的一个迁移文件,它抛出了错误
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;
use Jenssegers\Mongodb\Schema\Blueprint;
class CreateDriversTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::connection('mongodb')->create('drivers', function (Blueprint $collection) {
$collection->string('first_name');
$collection->string('last_name');
$collection->string('id_number');
$collection->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::connection('mongodb')->drop('drivers');
}
}
mySQL是主要的数据库连接
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=project
DB_CONNECTION_MONGO=mongodb
DB_HOST_MONGO=127.0.0.1
DB_PORT_MONGO=27017
DB_DATABASE_MONGO=project
如果我需要提供任何额外的信息或代码示例,请告诉我。我曾尝试使用文档中所述的内容,但出现了相同的错误。我不熟悉将MongoDB与Laravel一起使用,并且搜索过internet,但没有找到有效的解决方案
更新
我刚刚将Schema::connection('mongodb')->drop('drivers');
函数直接移动到Schema::connection('mongodb')->create('drivers'),…
数据库中的up()和集合中。因此似乎down()函数被忽略了
2018年11月8日更新
我曾尝试使用dropIfExists('drivers')
函数,但该集合仍然没有删除