【问题标题】:Errors in migration when installing the Laravel Voyager package安装 Laravel Voyager 包时出现迁移错误
【发布时间】:2017-09-22 11:20:54
【问题描述】:

我已经全新安装了 Laravel 5.5,但是当我尝试安装 Voyager 管理面板时出现此错误:

  [Illuminate\Database\QueryException]
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table `translations` add unique `translati
ons_table_name_column_name_foreign_key_locale_unique`(`table_name`,    `column_name`, `foreign_key`, `locale`))

配置

PHP 版本:7.0.10 MYSQL 版本:5.7.14

代码更新

我想我找到了相关代码:

        Schema::create('translations', function (Blueprint $table) {
        $table->increments('id');

        $table->string('table_name');
        $table->string('column_name');
        $table->integer('foreign_key')->unsigned();
        $table->string('locale');

        $table->text('value');

        $table->unique(['table_name', 'column_name', 'foreign_key', 'locale']); // SOURCE OF THE ERROR ?
    });

【问题讨论】:

  • 你能把这个`Schema::defaultStringLength(191);`添加到你的app/Providers/AppServiceProvider@boot
  • 已经完成了!!
  • 我也有同样的问题。你解决问题了吗?

标签: laravel laravel-5 migration


【解决方案1】:

您需要更新“mysql”的“config/database.php”。

'engine' => null

'engine' => 'InnoDB ROW_FORMAT=DYNAMIC',

同时更新“app/Providers/AppServiceProvider.php”

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        // Specified key was too long error, Laravel News post:
        Schema::defaultStringLength(191);
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

并在您的项目文件夹中运行这些命令。

php 工匠缓存:清除

php 工匠配置:清除

php artisan voyager:install --with-dummy

【讨论】:

    【解决方案2】:

    您的索引总长度太长。

    添加唯一索引的列不应像 VARCHAR 列那样长,因为索引会非常庞大​​且效率低下。

    【讨论】:

      【解决方案3】:

      这是一个已知的issue

      如果您不使用 Voyager 的多语言功能,只需取消注释 *******************_create_translations_table 中的行

      //  $table->unique(['table_name', 'column_name', 'foreign_key', 'locale']);
      

      或尝试将您的 MySql 数据库更新到 7.x

      【讨论】:

        猜你喜欢
        • 2018-03-24
        • 1970-01-01
        • 1970-01-01
        • 2018-05-02
        • 2020-08-02
        • 1970-01-01
        • 2018-05-03
        • 2021-10-20
        • 1970-01-01
        相关资源
        最近更新 更多