[Solved] Base table or view not found: 1146 Table Laravel 5

Im getting this error when I try to save data to mysql using Laravel 5, other forms and save() methods work fine but this one:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sistemal5.cotizacions' doesn't exist (SQL: insert into `cotizacions` (`customer_id`, `total`, `updated_at`, `created_at`) values (1501, 150.69, 2015-05-11 03:16:25, 2015-05-11 03:16:25))

Here is my Controller store method:

public function store(CotFormRequest $request)
        $quote = new Cotizacion;
        $quote->customer_id = Input::get('data.clientid');
        $quote->total = Input::get('data.totalAftertax');    

And here is my model:

<?php namespace AppModelsCotizacion;

use IlluminateDatabaseEloquentModel;

class Cotizacion extends Model {


I must be overlooking something really obvious cause i cant understand why Laravel is adding an “S” the table is cotizacion not cotizacions.

How can i troubleshoot this?

Enquirer: ray sn0w


Solution #1:

I’m guessing Laravel can’t determine the plural form of the word you used for your table name.

Just specify your table in the model as such:

class Cotizacion extends Model{
    public $table = "cotizacion";
Respondent: James Spence

Solution #2:

Check your migration file, maybe you are using Schema::table, like this:

Schema::table('table_name', function ($table)  {
    // ...

If you want to create a new table you must use Schema::create:

Schema::create('table_name', function ($table)  {
    // ...
Respondent: Inamur Rahman

Solution #3:

I faced this problem too in laravel 5.2 and if declaring the table name doesn’t work,it is probably because you have some wrong declaration or mistake in validation code in Request (If you are using one)

Respondent: sao

Solution #4:

If your error is not related to the issue of

Laravel can’t determine the plural form of the word you used for your
table name.

with this solution

and still have this error, try my approach. you should find the problem in the default “AppServiceProvider.php” or other
ServiceProviders defined for that application specifically or even in Kernel.php in AppConsole

This error happened for me and I solved it temporary and still couldn’t figure out the exact origin and description.

In my case the main problem for causing my table unable to migrate, is that I have running code/query on my “PermissionsServiceProvider.php” in the boot() method.

In the same way, maybe, you defined something in boot() method of AppServiceProvider.php or in the Kernel.php

So first check your Serviceproviders and disable code for a while, and run php artisan migrate and then undo changes in your code.

Respondent: panjeh

Solution #5:

Just run the command:

php artisan migrate:refresh --seed
Respondent: Abhi

Solution #6:

I also had this problem when doing migration => after performing php artisan migrate:refresh –seed command

“Base table or view not found: 1146 Table posts do not exist”
and I solved it, I was using “soft deletes” in a separate migration file, and my original migration for “posts” table which was responsible for creating the “posts” table was performing after the “soft deletes” migration in the databasemigration folder, I simply needed to rename the “posts” migration file name and put it before “softdeletes” migration to perform sooner.
the do the migration again => php artisan migrate:refresh –seed
it’s done.

Respondent: samad.naghipour

Solution #7:

When you are passing the custom request in the controller method, and your request file doesn’t follow the proper syntax or table name is changed, then laravel through this type of exception. I’ll show you in Example.

My Request code.
     public function rules()
            return [
                'name' => 'required|unique:posts|max:50',
                'description' => 'required',

But my table name is todos not posts so that's why it through "Base table or view not found: 1146 Table Laravel 7

    I forgot to change the table name in first index.
     public function rules()
            return [
                'name' => 'required|unique:todos|max:50',
                'description' => 'required',
Respondent: Hadi

Solution #8:

This problem occur due to wrong spell or undefined database name. Make sure your database name, table name and all column name is same as from phpmyadmin.

Thank You

Respondent: MD SHAYON

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy