php artisan migrateでマイグレーションしたところエラーが出てしまいました。
やったこととして、
App\Providers\AppServiceProvider.phpに
Schema::defaultStringLength(191);
を追加(古いDBに対応するため?)してみましたが解決しませんでした。
現在の状態として、もともとあったDB(mysqlで直接作成したもの)は削除しており、webアプリケーションはテーブルがないので動いてません。
App\Providers\AppServiceProvider.php
php
1<?php 2 3namespace App\Providers; 4 5use Illuminate\Support\ServiceProvider; 6use Illuminate\Support\Facades\Schema; 7 8 9class AppServiceProvider extends ServiceProvider 10{ 11 /** 12 * Bootstrap any application services. 13 * 14 * @return void 15 */ 16 public function boot() 17 { 18 // 19 Schema::defaultStringLength(191); 20 } 21 22 /** 23 * Register any application services. 24 * 25 * @return void 26 */ 27 public function register() 28 { 29 // 30 } 31} 32
2018_10_11_132756_create_events_table.php
php
1<?php 2 3use Illuminate\Support\Facades\Schema; 4use Illuminate\Database\Schema\Blueprint; 5use Illuminate\Database\Migrations\Migration; 6 7class CreateEventsTable extends Migration 8{ 9 /** 10 * Run the migrations. 11 * 12 * @return void 13 */ 14 public function up() 15 { 16 Schema::create('events', function (Blueprint $table) { 17 $table->increments('event_id', 11)->autoIncrement(); 18 $table->string('event_name', 100); 19 $table->text('event_info'); 20 $table->string('place_ken', 20); 21 $table->string('place_shi', 20); 22 $table->string('place_shosai', 100); 23 $table->string('palce_postalcode', 10); 24 $table->integer('capacity', 11); 25 $table->dateTime('accept_start'); 26 $table->dateTime(' accept_end'); 27 $table->dateTime('open_day'); 28 $table->dateTime('close_day'); 29 $table->integer('organizer_id', 11); 30 $table->integer('category', 11); 31 }); 32 } 33 34 /** 35 * Reverse the migrations. 36 * 37 * @return void 38 */ 39 public function down() 40 { 41 Schema::dropIfExists('events'); 42 } 43} 44
エラー内容
Migrating: 2018_10_11_132756_create_events_table Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key (SQL: create table `events` (`event_id` int unsigned not null auto_increment primary key, `event_name` varchar(100) not null, `event_info` text not null, `place_ken` varchar(20) not null, `place_shi` varchar(20) not null, `place_shosai` varchar(100) not null, `palce_postalcode` varchar(10) not null, `capacity` int not null auto_increment primary key, `accept_start` datetime not null, ` accept_end` datetime not null, `open_day` datetime not null, `close_day` datetime not null, `organizer_id` int not null auto_increment primary key, `category` int not null auto_increment primary key) default character set utf8mb4 collate 'utf8mb4_unicode_ci') at /Users/home/github/offgame/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 PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key") /Users/home/github/offgame/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458 2 PDOStatement::execute() /Users/home/github/offgame/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458 Please use the argument -v to see more details.
環境
- Laravel Framework 5.7.8
- mysql 5.7.21
- PHP Version 7.2.7
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/24 14:54