3
votes

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

2
is not its already pretty self explanatory? could you check in your test database for people table.. - Bagus Tesa
Did you execute the migrations before importing data? - Jerodev

2 Answers

2
votes

This error can be caused when your database table has not created correctly. You must to create your models and migration files first.

To create them you can run this command (for example):

 php artisan make:model People -m

Then, after all configurations in the People model class and in the migration file - run:

php artisan migrate 

This will create all the migration tables in the database. p.s. don't forget to check your .env file for the correct database name.

...
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=<your_database_name>
DB_USERNAME=<your_username>
DB_PASSWORD=<your_password>
 ...
0
votes

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!