16
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SQLSTATE[42S02]: Base table or view not found: 1146 Table '×××' doesn't exist (SQL: select * from `×××`)の解決方法

Last updated at Posted at 2021-02-01

Laravel初心者です。
オリジナルアプリを作成しています。

今回はその過程で出たエラーと解決方法を残しておきます。
理解が曖昧なところも多いため、ご指摘等ありましたらご連絡いただければ幸いです。

環境

Version
PHP 7.4.14
Laravel 8.24.0
mysql 8.0.23
docker 20.10.2
docker-compose 1.27.4

エラー発生

スクリーンショット 2021-02-01 20.07.03.png

SQLSTATE[42S02]: Base table or view not found: 1146 Table '×××' doesn't exist (SQL: select * from `×××`)

と出ました。

内容は
×××って名前のテーブルもしくはビューは見つからないよ
という意味みたいです。

画面下の方に
マイグレーションしたら?って出てるので

php artisan migrate

してみましたが

Nothing to migrate.

となりました。
確認で

php artisan migrate:status

でマイグレーションの確認をしたら全てYesになっている。
困りました。

解決

簡単でした!
こちらの記事を参考にさせて頂きました。
ありがとうございます!

記事の通りにapp/Models配下の該当のモデル名.phpを確認します。

app/Models/×××.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ××× extends Model
{
    use HasFactory;

    protected $table = "ここ";
}

上記のここというところに書くテーブル名が単数形になってました。
photosにしないといけないところをphotoにしてたのでエラーになっていました。

修正し無事に解決です!

16
8
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
16
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?