【问题标题】:RethinkDB- unable to migrate in Laravel 5.5RethinkDB-无法在 Laravel 5.5 中迁移
【发布时间】:2018-04-24 11:35:42
【问题描述】:

我正在尝试在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 

我在 repo 中查看了这个问题,但它在 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');
    }
}

提前致谢:)

【问题讨论】:

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


    【解决方案1】:

    通过此命令修复此问题

    php artisan migrate --database=rethinkdb
    

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

    问题#1和回购的Issue#39

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

    php artisan migrate --database=rethinkdb
    

    然后你会在Blueprint.php 中看到另一个错误

    [错误异常]
    duxet\RethinkDB\Schema\Blueprint::index($column, $options = NULL) 应该兼容 照亮\数据库\架构\蓝图::index($columns, $name = NULL, $算法 = NULL)

    您可以通过在Blueprint.php 中进行编辑来解决此问题,方法是替换

    public function index($column, $options = null)
    

    通过

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

    问题 #2Issue#41 声明为

    [Symfony\Component\Debug\Exception\FatalErrorException]
    duxet\Rethinkdb\Query\Builder::$operators 的访问级别必须为 公共(如在类 Illuminate\Database\Query\Builder 中)

    要解决此问题,您必须在 Builder.php 中进行编辑

    $operator 访问类型从protected 更改为public

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

    问题 #3

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

    为此,您必须在需要替换的地方编辑Builder.php

     public function groupBy()
    

    通过

     public function groupBy(...$groups)
    

    问题 #4

    现在在解决所有这些问题后,您会遇到我今天在解决所有这些问题时发现的另一个问题。

    [Symfony\Component\Debug\Exception\FatalThrowableError]
    调用成员函数supportsSchemaTransactions() on null

    要解决此问题,您需要执行以下步骤。 1.在src/Schema命名空间中创建一个文件Grammar.php并粘贴这段代码。

    <?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

    首先,添加这个

    use duxet\Rethinkdb\Schema\Grammar;
    

    然后在public function __construct(array $config) 里面添加这个

    $this->schemaGrammar = new Grammar();
    

    我在forked version 中修复了以上所有内容并提出了拉取请求。希望这会对您有所帮助,并且您不需要像我一样摸不着头脑:)

    更新

    11 月 13 日,pull request 被接受,现在你不需要做以下步骤,如果你发现任何问题仍然可以尝试。

    【讨论】:

      猜你喜欢
      • 2018-07-30
      • 1970-01-01
      • 1970-01-01
      • 2018-04-26
      • 2019-02-07
      • 2018-10-18
      • 1970-01-01
      • 2018-06-18
      相关资源
      最近更新 更多