Laravel-mongodb: error when php migrate refresh

Created on 31 Jan 2017  路  9Comments  路  Source: jenssegers/laravel-mongodb

when I run php artisan migrate:refresh
I got error like this
[ErrorException] Argument 2 passed to Illuminate\Database\Schema\Blueprint::build() must be an instance of Illuminate\Database\Schema\Grammars\Grammar, null given, cal led in /Users/adityabudiutomo/Documents/project/web/getboards/vendor/larave l/framework/src/Illuminate/Database/Schema/Builder.php on line 239 and defi ned

Most helpful comment

Here's a patch I used to temporarily fix this

--- vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/Schema/Builder.php.orig    2017-02-03 19:08:43.684919355 +0100
+++ vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/Schema/Builder.php 2017-02-03 19:08:14.395483413 +0100
@@ -128,6 +128,19 @@
         return $blueprint->drop();
     }

+    /**
+     * Drop a collection from the schema, if present.
+     *
+     * @param  string  $collection
+     * @return void
+     */
+    public function dropIfExists($collection)
+    {
+         if ($this->hasCollection($collection)) {
+              $this->drop($collection);
+         }
+    }
+
     /**
      * Create a new Blueprint.
      *

All 9 comments

Here's a patch I used to temporarily fix this

--- vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/Schema/Builder.php.orig    2017-02-03 19:08:43.684919355 +0100
+++ vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/Schema/Builder.php 2017-02-03 19:08:14.395483413 +0100
@@ -128,6 +128,19 @@
         return $blueprint->drop();
     }

+    /**
+     * Drop a collection from the schema, if present.
+     *
+     * @param  string  $collection
+     * @return void
+     */
+    public function dropIfExists($collection)
+    {
+         if ($this->hasCollection($collection)) {
+              $this->drop($collection);
+         }
+    }
+
     /**
      * Create a new Blueprint.
      *

How were you able to connect to the database in the first place. I can't do php artisan migrate. COuld you please help?

@migaliza This doesn't belong here, but - here's some ideas:

  • make sure you have use Jenssegers\Mongodb\Schema\Blueprint; in the migration file
  • check that you selected mongodb as the DB to use in the config file

"can't do php artisan migrate" is really vague, next time please post the actual error you got.

Thank you @MightyPork. Here is the exact error I am getting:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Parse error: syntax error, unexpected '('

@MightyPork your answer is useful

I've got a similar issue, can't do php artisan migrate and I get the following error:

[MongoDB\Exception\InvalidArgumentException]
$collectionName is invalid:

I'm just doing a simple schema create at the moment, any ideas?

I think it is better to replace dropIfExists with drop in your migrations or implement the dropIfExists logic using drop and hasCollection method like @MightyPork in your migrations.

a year and half later, I'm still using my "temporary" patch. @jenssegers is this closed because it's fixed, or...?

@MightyPork I have the same problem.I replace Schema::dropIfExists() with Schema::drop() , and it works.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

viacheslavpleshkov picture viacheslavpleshkov  路  3Comments

YSimple picture YSimple  路  3Comments

tomartailored picture tomartailored  路  3Comments

naveedyasin picture naveedyasin  路  3Comments

kschethan picture kschethan  路  3Comments