首页 > 解决方案 > 未定义的方法 defaultStringLength()

问题描述

我想在 laravel 项目中使用 Vinelab/Neoeloquent 包。早些时候,我使用 MySql 来存储我的数据。现在我想为此目的使用 neo4j。我"vinelab/neoeloquent":"1.4.7"在composer.json中添加了database.php

'default' => env('DB_CONNECTION','neo4j'), 在连接数组中

'neo4j' => [
'driver' => 'neo4j',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '7474'),
'username' => env('DB_USERNAME', 'neo4j'),
'password' => env('DB_PASSWORD', 'neo4j')
]

并在 app.php'Vinelab\NeoEloquent\NeoEloquentServiceProvider'

之后,composer 更新成功。此外,我将 .env 从我之前的 MySQL 配置更改为 neo4j 的配置

DB_CONNECTION=neo4j
DB_HOST=127.0.0.1
DB_PORT=7474
DB_DATABASE=neo4j
DB_USERNAME=neo4j
DB_PASSWORD=neo4j

毕竟,我遇到了一些问题:1.它无法识别迁移文件中的功能标签

public function up()
{
  Neo4jSchema::label('User', function(Blueprint $label) {
      $label->unique('email');
      $label->index('name');
  });
}

2.即使有这个问题,当我尝试迁移时,我遇到了以下问题

In Facade.php line 223:

Call to undefined method Vinelab\NeoEloquent\Schema\Builder::defaultStringLength()

请记住,在我更改 .env 文件后,我无法更新作曲家并得到同样的错误

Illuminate\Foundation\ComposerScripts::postAutoloadDump
@php artisan package:discover

In Facade.php line 223:

Call to undefined method Vinelab\NeoEloquent\Schema\Builder::defaultStringLength()

Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1
Failed to update packages for ./composer.json.

标签: phplaravelneo4j

解决方案


尝试用这个编辑你的AppServiceProvider.php

use Illuminate\Support\Facades\Schema;
public function boot() { Schema::defaultStringLength(191); }


推荐阅读