Q&A
問題点
php artisan db:seed --class=TasksTableSeederを行った際に「SQLSTATE[42S22]: Column not found: 1054 Unknown column 'folder_id' in 'field list'」とエラー表示がされます。
TasksTableSeeder.phpにエラー箇所であるUnknown column 'folder_id'が存在しているのになぜかエラーが出てしまう。
発生している問題・エラーメッセージ
vagrant@homestead:~/code/plan-b$ php artisan db:seed --class=TasksTableSeeder Illuminate\Database\QueryException : SQLSTATE[42S22]: Column not found: 1054 Unknown column 'folder_id' in 'field list' (SQL: insert into `tasks` (`folder_id`, `title`, `status`, `due_date`, `created_at`, `updated_at`) values (1, サンプルタスク 1, 1, 2019-08-18 03:40:27, 2019-08-17 03:40:27, 2019-08-17 03:40:27)) at /home/vagrant/code/plan-b/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| } 668| Exception trace: 1 PDOException::("SQLSTATE[42S22]: Column not found: 1054 Unknown column 'folder_id' in 'field list'") /home/vagrant/code/plan-b/vendor/laravel/framework/src/Illuminate/Database/Connection.php:452 2 PDO::prepare("insert into `tasks` (`folder_id`, `title`, `status`, `due_date`, `created_at`, `updated_at`) values (?, ?, ?, ?, ?, ?)") /home/vagrant/code/plan-b/vendor/laravel/framework/src/Illuminate/Database/Connection.php:452 Please use the argument -v to see more details.
TasksTableSeeder.php
<?php use Carbon\Carbon; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; class TasksTableSeeder extends Seeder { /** * Run the database seeds. * * @return void */ public function run() { foreach (range(1, 3) as $num) { DB::table('tasks')->insert([ 'folder_id' => 1, 'title' => "サンプルタスク {$num}", 'status' => $num, 'due_date' => Carbon::now()->addDay($num), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now(), ]); } } }
試したこと
タイムスタンプを無効にすればいいとのことでしたが、$timestamps = false;をテーブルのfunction内に設置してもエラーが変わりませんでした。
補足情報(FW/ツールのバージョンなど)
OS:mac
homestead環境
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
2019/08/17 04:21
2019/08/17 05:47