WebStack-Laravel icon indicating copy to clipboard operation
WebStack-Laravel copied to clipboard

一个数据迁移问题

Open iyzyi opened this issue 5 years ago • 0 comments

问题

/opt/navi # php artisan key:generate
Application key [base64:BoW/kKaZJNVPuyLO9CjTExztgqHNplDmHM5/xpX5Cac=] set successfully.
/opt/navi # php artisan migrate:refresh --seed
Rolling back: 2019_01_21_144821_create_sites_table
Rolled back:  2019_01_21_144821_create_sites_table
Rolling back: 2019_01_21_120954_create_categories_table
Rolled back:  2019_01_21_120954_create_categories_table
Rolling back: 2017_07_17_040159_create_config_table
Rolled back:  2017_07_17_040159_create_config_table
Rolling back: 2016_01_04_173148_create_admin_tables
Rolled back:  2016_01_04_173148_create_admin_tables

In Connection.php line 664:

  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t
  oo long; max key length is 767 bytes (SQL: alter table `admin_config` add u
  nique `admin_config_name_unique`(`name`))


In PDOStatement.php line 119:

  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t
  oo long; max key length is 767 bytes


In PDOStatement.php line 117:

  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t
  oo long; max key length is 767 bytes

解决

./app/Providers/AppServiceProvider.phppublic function boot()中添加Schema::defaultStringLength(191);,如下:

    public function boot()
    {
        Site::observe(SiteObserver::class);

        $table = config('admin.extensions.config.table', 'admin_config');
        if (Schema::hasTable($table)) {
            Config::load();
        }

        Schema::defaultStringLength(191);
    }

参考

Laravel 5.4 常见错误:Specified key was too long

iyzyi avatar Feb 05 '20 05:02 iyzyi