laravel - 安装 Laravel Voyager 包时迁移错误

标签 laravel laravel-5 migration

我全新安装了 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 ?
    });

最佳答案

您需要更新“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 artisan 缓存:清除

php artisan 配置:清除

php artisan voyager:install --with-dummy

关于laravel - 安装 Laravel Voyager 包时迁移错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46363547/

相关文章:

Mysql 表关系 - 迁移 LARAVEL

php - 如何构建多站点管理器应用程序?

php - Laravel 工厂和播种 : Static array of arrays

javascript - Laravel 5.2 使用 jQuery 添加变量来请求

laravel - 自动刷新所有表单的CSRF Token

node.js - Laravel Elixir 命令的异步执行

php - 使用同步方法 laravel 在 pivot 中进行软删除

php - Laravel 正则表达式与 JPG 匹配 Url 不起作用

migration - 将 Nexus 存储库移至不同的计算机

php - Doctrine2中的多对多关系导致迁移时出现重复错误