RethinkDB-无法在Laravel 5.5中迁移

时间:2017-11-11 09:23:07

标签: php laravel rethinkdb laravel-5.5 laravel-migrations

我正在尝试在此git repo之后创建一个RethinkDB + Laravel的演示,但我陷入困境将迁移我的迁移。当我尝试使用php artisan migrate迁移时出现此错误

[Symfony\Component\Debug\Exception\FatalThrowableError]                                                                                                      
  Type error: Argument 1 passed to Users::{closure}() must be an instance of duxet\Rethinkdb\Schema\Blueprint, instance of Illuminate\Database\Sc  
  hema\Blueprint given, called in /opt/lampp/htdocs/xyzz-laravel/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php on line 164 

我在回购中调查了这个问题,但它在bug中列出并没有得到妥善解决。是否有人遇到过此问题,并且有关于如何修复此错误的想法?

这是我的移植工作。

<?php

use Illuminate\Support\Facades\Schema;
use duxet\Rethinkdb\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class Users extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users',function (Blueprint $table){
            $table->increments('id');
            $table->string('name');
            $table->timestamps();
        });
    }

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

提前致谢:)

1 个答案:

答案 0 :(得分:1)

通过此命令解决此问题

php artisan migrate --database=rethinkdb

因为我DB_CONNECTION='rethinkdb文件中有database.php,当您收到此错误时,您也会发现其他问题,因此我已经分叉this repo并请求了拉取请求。直到那时你可以自己解决它。

回复

问题#1 Issue#39

为此,您需要在迁移时指定数据库名称,如果您有多个dbs,则默认情况下它将为Illuminate\Database\Schema\Blueprint这样

php artisan migrate --database=rethinkdb

然后您将在此处声明的Blueprint.php中收到另一个错误

  

[ErrorException]
  声明duxet \ RethinkDB \ Schema \ Blueprint :: index($ column,   $ options = NULL)应该兼容   Illuminate \ Database \ Schema \ Blueprint :: index($ columns,$ name =   NULL,$ algorithm = NULL)

您可以通过替换

Blueprint.php进行修改来解决此问题
public function index($column, $options = null)

通过

public function index($columns, $name = NULL, $algorithm = NULL)

问题#2 Issue#41表示为

  

[Symfony的\元器件\调试\异常\ FatalErrorException]
  访问级别为duxet \ Rethinkdb \ Query \ Builder :: $运算符必须是   public(如类Illuminate \ Database \ Query \ Builder)

要解决此问题,您必须在Builder.php

进行修改

$operator访问类型从public

更改为protected
public $operators = [
        '=', '<', '>', '<=', '>=', '<>', '!=',
        'like', 'not like', 'between', 'ilike',
        '&', '|', '^', '<<', '>>',
        'rlike', 'regexp', 'not regexp',
        '~', '~*', '!~', '!~*',
        'contains', 'exists', 'type', 'mod', 'size',
    ];

问题#3

之后你会发现另一个问题,也就是有Issue#42

的回购

为此,您需要修改需要替换的Builder.php

 public function groupBy()

通过

 public function groupBy(...$groups)

问题#4

现在在解决了所有这些问题之后,您将遇到另一个问题,我今天在解决所有这些问题时发现了自己。

  

[Symfony的\元器件\调试\异常\ FatalThrowableError]
  在null

上调用成员函数supportsSchemaTransactions()

要解决此问题,您需要按照以下步骤操作。 1.在Grammar.php命名空间中创建文件src/Schema并粘贴此代码。

<?php

namespace duxet\RethinkDB\Schema;

use Illuminate\Database\Schema\Grammars\Grammar as BaseGrammar;

/**
 * Class Grammar
 *
 * @package Moloquent\Schema
 */
class Grammar extends BaseGrammar {
}
  1. 现在您需要修改Connection.php
  2. 首先,添加此

    use duxet\Rethinkdb\Schema\Grammar;
    

    然后在public function __construct(array $config)内添加此

    $this->schemaGrammar = new Grammar();
    

    我在forked version修复了上述所有内容,并提出了拉取请求。希望这会对你有所帮助,你不需要像我一样挠头:)

    <强>更新

    在11月11日Novemeber,拉取请求被接受,现在如果您发现任何问题,您仍然无需执行以下步骤。

相关问题