質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
MySQL

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Laravel 5

Laravel 5は、PHPフレームワークLaravelの最新バージョンで、2014年11月に発表予定です。ディレクトリ構造がが現行版より大幅に変更されるほか、メソッドインジェクションやFormRequestの利用が可能になります。

Q&A

解決済

2回答

1380閲覧

Laravelのマグレーションができません。

HearthXml

総合スコア51

MySQL

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Laravel 5

Laravel 5は、PHPフレームワークLaravelの最新バージョンで、2014年11月に発表予定です。ディレクトリ構造がが現行版より大幅に変更されるほか、メソッドインジェクションやFormRequestの利用が可能になります。

0グッド

0クリップ

投稿2018/10/24 13:41

編集2018/10/24 14:13

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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

ベストアンサー

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

とエラーが出ているので、autoIncrementのカラムが複数定義されている事がエラーの原因です。

integer()の第2引数はautoIncrementのフラグなので、ここに数字を渡してはいけないのではないでしょうか。
public function integer($column, $autoIncrement = false, $unsigned = false)

integerのところを全て以下のように修正してみてはどうでしょう。
$table->integer('capacity', 11);

$table->integer('capacity');

投稿2018/10/24 14:18

mrkmyki

総合スコア325

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

HearthXml

2018/10/24 14:54

第二引数はstringと同じlengthだと勘違いして設定してました。 無事解決しました。ありがとうございます。
guest

0

Google翻訳を使っても良いのでエラーを読みましょう。

Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key

下の行が怪しいです。

php

1$table->increments('event_id', 11)->autoIncrement();

これを

$table->increments('id');

に直して下さい。
->autoIncrement() は不要と思います。
また、Laravelでは主キーの命名はどのテーブルも id としておくのが無難です。
主キーの名前を変更することは可能ですが、別に設定が必要になるので特に初心者であれば変えない方が良いです。

それから、

$table->dateTime(' accept_end');

このような不要な空白は除去しましょう。

投稿2018/10/24 14:12

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問