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

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

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

Q&A

解決済

1回答

1760閲覧

Laravelにて突然SQLのエラーが発生するようになった

moritaryo

総合スコア11

0グッド

0クリップ

投稿2022/04/05 18:41

編集2022/04/07 07:23

laravelについての質問です。

Controllerでcreateメソッドを使っていて今までは問題なく動いていたのですが、突然エラーを出すようになってしまいました。ご教授お願いいたします。

SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name 'example' select count(*) as aggregate from `example `where `name` = a
* @throws \Illuminate\Database\QueryException */ protected function runQueryCallback($query, $bindings, Closure $callback) { // To execute the statement, we'll simply call the callback, which will actually // run the SQL against the PDO connection. Then we can calculate the time it // took to execute and log the query SQL, bindings and time in our memory. try { return $callback($query, $bindings); } // If an exception occurs when attempting to run a query, we'll format the error // message to include the bindings with SQL, which will make this exception a // lot more helpful to the developer instead of just the database's errors. catch (Exception $e) { throw new QueryException( $query, $this->prepareBindings($bindings), $e ); } } /** * Log a query in the connection's query log. * * @param string $query * @param array $bindings * @param float|null $time * @return void */

tableの設定などは動いていた時から変わっておらず、キャッシュとかの関係なのかな、と思い消してみましたが変わりませんでした。

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

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

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

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

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

m.ts10806

2022/04/06 01:42

一時テーブルとかでしょうか。 ものすごく長い名前とか。 エラーは基本略さず訳さず提示を。 あと、コードやテーブル定義など一通りあったほうが良いです。他者が
guest

回答1

0

自己解決

直りました。どうやらリクエストの部分で

"name" => "required |unique:example| max:20",

のexampleの後ろにスペースがあったことでexampleテーブルではなくexample テーブルを探してしまっていたことが原因でした。

今回は原因がはっきりせず、分かりづらい質問になってしまい申し訳ありませんでした。

投稿2022/04/09 08:21

moritaryo

総合スコア11

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問