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

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

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

SQLiteはリレーショナルデータベース管理システムの1つで、サーバーではなくライブラリとして使用されている。

Q&A

解決済

2回答

9495閲覧

SQlite エラー 1 no such table:  の原因

dda

総合スコア33

SQLite

SQLiteはリレーショナルデータベース管理システムの1つで、サーバーではなくライブラリとして使用されている。

0グッド

0クリップ

投稿2020/03/03 03:52

編集2020/03/03 04:18

laravel を使って適当にログイン画面を作っています。

以下のindex.blade.phpにてID、PWを送信し、コントローラー内でそのデータをsqlite内のテーブルに挿入するという操作をしたいのですが。

送信するとSQLSTATE[HY000]: General error: 1 no such table: member (SQL: insert into member (ID, PW) values (:ID, :PW))というエラーが発生します。

.envのSESSION_DRIVERはfileに設定されています。

↓index.blade.php

<!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <title>Login Practice</title> </head> <body> <h1> Wellcome!</h1> <form action="/login/clear" method="post"> @csrf <table> <tr><th>ID:</th><td><input type="text" name="id"></td></tr> <tr><th>PW:</th><td><input type="text" name="pw"></td></tr> <tr><th></th><td><input type="submit" value="send"></td></tr> </table> </form> </body> </html>

↓LoginController.php

<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Http\Response; use Illuminate\Support\Facades\DB; class LoginController extends Controller { public function index(){ return view('login.index'); } public function clear(Request $request){ $in = [ 'ID' => $request->id, 'PW' => $request->pw, ]; DB::insert('insert into member (ID, PW) values (:ID, :PW)', $in); $data = DB::select('select * from member'); return view('login.clear', ['cells' => '$data']); } }

イメージ説明

エラー発生源を下記にのせておきます。
C:\Users\fghjz.LAPTOP-VM64TKHN\Desktop\laravelapp\vendor\laravel\framework\src\Illuminate\Database\Connection.php:669

throw new QueryException(     下記のこの部分が669行目になります。
{ // 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 { $result = $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 ); } return $result; }

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

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

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

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

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

dda

2020/03/03 04:10

コメントありがとうございます。 SQLSTATE[HY000]: General error: 1 no such table: member (SQL: insert into member (ID, PW) values (:ID, :PW)) エラーメッセージはこちらです。 画像はテーブル作成の証拠として載せました。
guest

回答2

0

自己解決

コマンドプロンプからsqliteに接続し、テーブルを作成していたことがerrorの原因であったことが判明しました。
migrationを利用して作成すると正常に作動しました。

投稿2020/03/10 04:48

dda

総合スコア33

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

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

0

SQLSTATE[HY000]: General error: 1 no such table: member (SQL: insert into member (ID, PW) values (:ID, :PW))というエラーが発生します。

そんなテーブルはないよ、って怒られています。
CREATE TALE member ...
が実行されていません。

投稿2020/03/03 04:02

Orlofsky

総合スコア16415

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

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

dda

2020/03/03 04:12

解答ありがとうございます。 同じテーブルを作ろうとしたら Error: table 'member' already existsと表示されたので作成されています。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問