why Base table : 1146 ‘database.tables’ doesn’t exist laravel 5

This is the very common error occurs for beginners.

Error is like, the table is not exist which the user wants to use”.

As per the laravel documentation, it is good to make the table name in plurals.

For example you have given the table name is “user” .

But laravel is searching for the table name as “users”, because by the documentation name should be “users” ,that’s why  error is occuring.
So for resolving this we have to define the exact table name in the model as we have given the table name:-

For Example – We have a shayari model class looking like this

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class shayari extends Model
{
protected $fillable = [‘cat_id’,’sub_cat_id’,’image’,’status’];
}

In above model class we have given statically our exact table name, which we wants to use.

Than above model class will looking like this after the updation.

class shayari extends Model
{
protected $table = ‘shayari ‘;
protected $fillable = [‘cat_id’,’sub_cat_id’,’image’,’status’];
}

As we have the shayari model.In which we can clearly see that we have mentioned the exact table name.

So laravel will not looking for a plural name of a table and it will not throw  “table does not exist error”.

Check it also

check for the documentation

2 thoughts on “why Base table : 1146 ‘database.tables’ doesn’t exist laravel 5”

Leave a Reply

Your email address will not be published. Required fields are marked *