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

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

新規登録して質問してみよう
ただいま回答率
85.50%
Laravel 6

Laravel 6は、オープンソースなPHPのフレームワーク。Webアプリケーションの開発に適しており、バージョン6はLTSです。5.8での向上に加えて、セマンティックバージョニングの採用やLaravel Vaporとのコンパチビリティなどが変更されています。

PHP

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

Q&A

解決済

1回答

613閲覧

マイグレーションができなくて困っています。原因不明です。

haruatu

総合スコア89

Laravel 6

Laravel 6は、オープンソースなPHPのフレームワーク。Webアプリケーションの開発に適しており、バージョン6はLTSです。5.8での向上に加えて、セマンティックバージョニングの採用やLaravel Vaporとのコンパチビリティなどが変更されています。

PHP

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

0グッド

0クリップ

投稿2022/02/05 19:42

編集2022/02/08 08:10

下記の内容でマイグレーションをしたいのですが、出来なくて困っています。ネットでも調べてみたのですが、何が間違っているのかわからない状態です。

public function up() { Schema::create('comics', function (Blueprint $table) { $table->bigIncrements('id'); $table->integer('book_booksGenreId')->unsigned(); $table->string('book_title')->unsigned(); $table->string('book_author')->unsigned(); $table->text('book_largeImageUrl')->unsigned(); $table->timestamps(); }); }

id以外はunsigned()していますが、親テーブルの内容は下記の通りです。

+---------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | title | varchar(255) | NO | | NULL | | | link | varchar(255) | YES | | NULL | | | author | varchar(255) | NO | | NULL | | | category | varchar(255) | YES | | NULL | | | guid | text | YES | | NULL | | | isbn | varchar(255) | YES | | NULL | | | booksGenreId | varchar(255) | YES | | NULL | | | publisherName | varchar(255) | YES | | NULL | | | largeImageUrl | text | YES | | NULL | | | created_at | timestamp | YES | | NULL | | | updated_at | timestamp | YES | | NULL | | +---------------+------------------+------+-----+---------+----------------+ 12 rows in set (0.01 sec)

マイグレーションしようと$php artisan migrateをすると下記のようになります

$ php artisan migrate Migrating: 2022_02_04_164257_create_comics_table Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'unsigned not null, `book_author` varchar(255) unsigned not null, `book_largeI...' at line 1 (SQL: create table `comics` (`id` bigint unsigned not null auto_increment primary key, `book_booksGenreId` int unsigned not null, `book_title` varchar(255) unsigned not null, `book_author` varchar(255) unsigned not null, `book_largeImageUrl` text unsigned not null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci') at /home/ec2-user/environment/book/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669 665| // If an exception occurs when attempting to run a query, we'll format the error 666| // message to include the bindings with SQL, which will make this exception a 667| // lot more helpful to the developer instead of just the database's errors. 668| catch (Exception $e) { > 669| throw new QueryException( 670| $query, $this->prepareBindings($bindings), $e 671| ); 672| } 673| Exception trace: 1 PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'unsigned not null, `book_author` varchar(255) unsigned not null, `book_largeI...' at line 1") /home/ec2-user/environment/book/vendor/laravel/framework/src/Illuminate/Database/Connection.php:457 2 PDO::prepare() /home/ec2-user/environment/book/vendor/laravel/framework/src/Illuminate/Database/Connection.php:457 Please use the argument -v to see more details.

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

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

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

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

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

CHERRY

2022/02/05 21:42

できないというのは、どのような動作をするのでしょうか? 何かメッセージが標示されるのですか?
YT0014

2022/02/07 06:28

string型のunsignedとは、何を指定されているおつもりなのでしょうか?
haruatu

2022/02/07 19:14

unsignedを指摘されてようやくわかりました。[book_title]、[book_author]、[book_largeImageUrl]の不要なunsignedを消すことで解決できました。ありがとうございました。
guest

回答1

0

自己解決

自己解決というよりは「質問への追記・修正の依頼」の意見のおかげで解決できました。

public function up() { Schema::create('comics', function (Blueprint $table) { $table->bigIncrements('id'); $table->integer('book_booksGenreId')->unsigned(); $table->string('book_title')->unsigned(); $table->string('book_author')->unsigned(); $table->text('book_largeImageUrl')->unsigned(); $table->timestamps(); }); }

                        ↓

public function up() { Schema::create('comics', function (Blueprint $table) { $table->bigIncrements('id'); $table->integer('book_booksGenreId')->unsigned(); $table->string('book_title'); $table->string('book_author'); $table->text('book_largeImageUrl'); $table->timestamps(); }); }

に変更したら直りました。unsignedの使い方を間違えていたようです。

投稿2022/02/07 19:21

haruatu

総合スコア89

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

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

YT0014

2022/02/07 23:10

解決したようで何よりです。 お役に立てたのなら幸いです。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問