0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Laravel における SQLSTATE[42S02]: Base table or view not found:

Posted at

Laravel Sail 起動時のエラーと対応

発生したエラー

./vendor/bin/sail up -d を実行した際に、以下のエラーが発生。

スクリーンショット 2025-03-13 22.02.31.png

これは、Laravel の sessions テーブルがデータベースに存在しないため発生している。

マイグレーションの実行

エラーを解決するため、以下のコマンドを実行。

./vendor/bin/sail artisan migrate

を実行したところ以下のようになった。

スクリーンショット 2025-03-13 22.11.53.png

migrate を実行した際に、以下のエラーが発生した。

SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'image'

これは、posts テーブルに image カラムを追加しようとしたが、すでに存在している ために発生しているようだ。
そこで

直前の変更を取り消しするために

./vendor/bin/sail artisan migrate:rollback --step=1
./vendor/bin/sail artisan migrate

を実行し、マイグレーションファイル (2025_03_11_085257_add_image_to_posts_table.php) を開いて

image カラムがすでに存在している場合は追加しないように変更した。

public function up()
{
    Schema::table('posts', function (Blueprint $table) {
        if (!Schema::hasColumn('posts', 'image')) {
            $table->string('image')->nullable();
        }
    });
}
./vendor/bin/sail artisan migrate

を実行して無事エラーは解決。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?