Illuminate\Database\QueryException with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'test.people' doesn't exist

Viewed 13880

i made a migration named persons while i want to import data useing tinker then error showing i made a migration named persons while i want to import data useing tinker then error showing Illuminate\Database\QueryException with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'test.people' doesn't exist (SQL: selec

3 Answers

One should be sure what model name are they using to create a model and what the error is coming. LARAVEL naming convention adds-up 's' assuming the table name ends with 's', e.g, in case you create a model with the name of 'dummy_project' as well as you have table 'dummy_project' it will add 's' to the end and if you run App\dummy_project in the tinker, it will produce the error:

*Illuminate/Database/QueryException with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'tutorial.dummy_projects' doesn't exist (SQL: select * from dummy_projects)'*

All we need to do is to add the following line of code into the model: protected $table = 'table_name'; === explaination ===

In case your table name is 'dummy_project' and you created a model name is 'dummy_project' too, the code in the model should be like following: *

**<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class dummy_project extends Model
{
    **protected $table = 'dummy_project';**
}**

* Please bear in mind, the model_name can be different than the table name, but 'protected $table = 'table_name' ' should always refer to the relevant table name in the DATABASE!

You must create the table by hand in the database so I will solve it because if you verify your database the table does not exist, so the warning.

Related