前提・実現したいこと
シーディングを実行したいです。
発生している問題・エラーメッセージ
php artisan make::seeder PeopleTableSeederとコマンドプロンプトに打ち込み、シーダーファイルを作成し、シーダーファイルを登録する為、DatabaseSeeder.phpに登録処理を記述しました。
そして、シーディングを実行する為、「php artisan db::seed」としたのですが以下のエラーが発生してしまいました
「 Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1 no such table: people (SQL: insert into "people" ("name", "mail", "age") values (taro, taro@yamada.jp, 12))」
以下は、databaseファイル内のconnection.phpのコードです。
ampp\htdocs\laravelapp\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664 660| // If an exception occurs when attempting to run a query, we'll format the error 661| // message to include the bindings with SQL, which will make this exception a 662| // lot more helpful to the developer instead of just the database's errors. 663| catch (Exception $e) { > 664| throw new QueryException( 665| $query, $this->prepareBindings($bindings), $e 666| ); 667| }
該当のソースコード
以下は、PeopleTableSeederです。
php
1<?php 2 3use Illuminate\Database\Seeder; 4use Illuminate\Support\Facades\DB; 5 6class PeopleTableSeeder extends Seeder 7{ 8 /** 9 * Run the database seeds. 10 * 11 * @return void 12 */ 13 public function run() 14 { 15 $param = [ 16 'name' => 'taro', 17 'mail'=> 'taro@yamada.jp', 18 'age' => 12, 19 ]; 20 DB::table('people')->insert($param); 21 22 $param = [ 23 'name' => 'hanako', 24 'mail' => 'hanako@flower.jp', 25 'age' => 34, 26 ]; 27 DB::table('people')->insert($param); 28 29 $param = [ 30 'name' => 'sachiko', 31 'mail' => 'sachiko@happy.jp', 32 'age' => 56, 33 ]; 34 DB::table('people')->insert($param); 35 } 36} 37
以下は、DatabaseSeeder.phpです
php
1<?php 2 3use Illuminate\Database\Seeder; 4 5class DatabaseSeeder extends Seeder 6{ 7 /** 8 * Seed the application's database. 9 * 10 * @return void 11 */ 12 public function run() 13 { 14 $this->call(PeopleTableSeeder::class); 15 } 16} 17
試したこと
エラー「 1 no such table:」と出ていたので、 select count(*) from sqlite_master where type='table' and name='people';とコマンドに打ち込んだのですが、「1」が返ってきた為、テーブルは存在しているものと思われます。
補足情報(FW/ツールのバージョンなど)
laravelのバージョンは5.8
phpは、7.3.1
OSはwindows10です
追記です
以下は、php artisan make:migration create_people_tableとし、作成したマイグレーションファイルになります。
<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreatePeopleTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('people', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('mail'); $table->integer('age'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('people'); } }
データベースファイル名はdatabase.sqliteです。
ファイルのパスは「C:\xampp\htdocs\laravelapp\database」です。

回答2件
あなたの回答
tips
プレビュー