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

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

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

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

Q&A

解決済

1回答

4283閲覧

Laravelのphp artisan migrate:refreshを行ったときのエラー

nakatai

総合スコア3

Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

0グッド

0クリップ

投稿2021/02/04 09:44

前提・実現したいこと

Laravelでアプリケーションを開発中、php artisan migrate:refreshにおいてエラーが発生しました

発生している問題・エラーメッセージ

エラーメッセージ Rolling back: 2014_10_12_000000_create_users_table Illuminate\Database\QueryException SQLSTATE[23000]: Integrity constraint violation: 1217 Cannot delete or update a parent row: a foreign key constraint fails (SQL: drop table if exists `users`) at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671 667| // If an exception occurs when attempting to run a query, we'll format the error 668| // message to include the bindings with SQL, which will make this exception a 669| // lot more helpful to the developer instead of just the database's errors. 670| catch (Exception $e) { > 671| throw new QueryException( 672| $query, $this->prepareBindings($bindings), $e 673| ); 674| } 675| +9 vendor frames 10 database/migrations/2014_10_12_000000_create_users_table.php:34 Illuminate\Support\Facades\Facade::__callStatic("dropIfExists") +34 vendor frames 45 artisan:37 Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

該当のソースコード

Laravel

1ソースコード 2<?php 3 4use Illuminate\Database\Migrations\Migration; 5use Illuminate\Database\Schema\Blueprint; 6use Illuminate\Support\Facades\Schema; 7 8class CreateAppTables extends Migration 9{ 10 /** 11 * Run the migrations. 12 * 13 * @return void 14 */ 15 public function up() 16 { 17 Schema::create('item_conditions', function (Blueprint $table) { 18 $table->id(); 19 20 $table->timestamps(); 21 }); 22 23 Schema::create('primary_categories', function (Blueprint $table) { 24 $table->id(); 25 26 $table->timestamps(); 27 }); 28 29 Schema::create('secondary_categories', function (Blueprint $table) { 30 $table->id(); 31 $table->unsignedBigInteger('primary_id'); 32 33 $table->timestamps(); 34 35 $table->foreign('primary_category_id')->references('id')->on('primary_categories'); 36 }); 37 38 //itemsテーブル 39 Schema::create('items', function (Blueprint $table) { 40 $table->id(); 41 $table->unsignedBigInteger('seller_id'); 42 $table->unsignedBigInteger('buyer_id'); 43 $table->unsignedBigInteger('item_condition_id'); 44 $table->unsignedBigInteger('secondary_category_id'); 45 46 $table->timestamps(); 47 48 $table->foreign('seller_id')->references('id')->on('users'); 49 $table->foreign('buyer_id')->references('id')->on('users'); 50 $table->foreign('item_condition_id')->references('id')->on('item_conditions'); 51 $table->foreign('secondary_category_id')->references('id')->on('secondary_categorieså'); 52 }); 53 54 } 55 56 /** 57 * Reverse the migrations. 58 * 59 * @return void 60 */ 61 public function down() 62 { 63 Schema::dropIfExists('items'); 64 Schema::dropIfExists('item_conditions'); 65 Schema::dropIfExists('secondary_categories'); 66 Schema::dropIfExists('primary_categories'); 67 } 68}

試したこと

idと外部キーのデータ型が合っていなかったり、dropするテーブルの順序を間違えるとエラーが起こるらしいですが、全て見直しても合っていると思う

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

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

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

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

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

guest

回答1

0

ベストアンサー

php artisan migrate:refresh でだめな場合は
php artisan migrate:fresh でどうでしょうか。

投稿2021/02/04 15:12

Lulucom

総合スコア1899

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問