ユーザ用ツール

サイト用ツール


サイドバー

このページの翻訳:



最近の更新



Tag Cloud

11_php:02_framework:01_laravel:13_laravel-admin

文書の過去の版を表示しています。


13 laravel-admin

Database用意

.env

APP_URL=http://hoge.hogehoge.com

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=XXXXXXX
DB_USERNAME=XXXXXXX
DB_PASSWORD=XXXXXXX

インストール

laravel newの後で実行

composer require encore/laravel-admin
php artisan vendor:publish --provider="Encore\Admin\AdminServiceProvider"
php artisan admin:install

エラー1.

$ php artisan admin:install
Migrating: 2014_10_12_000000_create_users_table

   Illuminate\Database\QueryException  : SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists (SQL: create table `users` (`id` int unsigned not null auto_increment primary key, `name` varchar(255) not null, `email` varchar(255) not null, `email_verified_at` timestamp null, `password` varchar(255) not null, `remember_token` varchar(100) null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8 collate 'utf8_unicode_ci')

  at /var/www/vhost/portal.kumolabo.com/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }
    668|

  Exception trace:

  1   Doctrine\DBAL\Driver\PDOException::("SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists")
      /var/www/vhost/portal.kumolabo.com/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:119

  2   PDOException::("SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists")
      /var/www/vhost/portal.kumolabo.com/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:117

  Please use the argument -v to see more details.

条件

Laravel5.4以上
MySQL5.7.7未満

原因

MySQL5.7.7以前のバージョンでは、PRIMARY_KEYおよびUNIQUE_KEYを付けたカラムには最大767bytesまでしか入らない。

対策

1.MySQLのバージョンを5.7.7以上にアップグレード

5.7.7以上にすれば、PRIMARY_KEYおよびUNIQUE_KEYを付けたカラムに767bytes以上のデータが入る。

2.charasetをutf8mb4から変更

laravel側のcharsetをUTF-8に変える。
laravel5.3までは、charsetの標準設定はUTF-8だった。

$ cat config/database.php  | grep utf8mb4
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            
            ↓
            
$ cat config/database.php  | grep utf8mb4
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',            

3.カラムの最大長を変更し、767bytes以上の文字列が入らないようにする

varchar(191) のカラムを作成すれば、191 * 4 = 764bytesのため、エラーが発生しない。

app/Providers/AppServiceProvider.php

use Illuminate\Support\Facades\Schema;

public function boot()
{
    Schema::defaultStringLength(191);
}

エラー2.

Disk [admin] not configured, please add a disk config in `config/filesystems.php`.

対応方法

config/filesystems.phpに下記を追加する。

config/filesystems.php

'disks' => [
    ... ,
    
    'admin' => [
        'driver' => 'local',
        'root' => public_path('uploads'),
        'visibility' => 'public',
        'url' => env('APP_URL').'/uploads',
    ],
],
11_php/02_framework/01_laravel/13_laravel-admin.1553951476.txt.gz · 最終更新: 2019/03/30 22:11 by matsui