Base Table or View Not Found: 1146 Table Laravel 5

Base table or view not found: 1146 Table Laravel 5

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";

How to fix error Base table or view not found: 1146 Table laravel relationship table?

It seems Laravel is trying to use category_posts table (because of many-to-many relationship). But you don't have this table, because you've created category_post table. Change name of the table to category_posts.

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'ums.people' doesn't exist

Laravel Eloquent follows a convention of naming tables for the model class - it's generally the snake_case plural of the model class name in lower case.

So in this case the model is called Person and eloquent will try to find a table named people for the model. If you have the table as persons for the model Person you will need to ensure that table name is specified on the model class

class Person extends Model
{
protected $table = 'persons';

// Rest of the model class code
}

Laravel Docs - Eloquent - Table Names

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel_abonamenty2.currencies' doesn't exist

Because the plural of currency is currencies and not currencys. Laravel automatically detects the table name of the snake case plural name of the model. documentation

In your model you can specify another table name like:

protected $table = 'currencys';

With that laravel will search the currencys table.

Base table or view not found: 1146 Table Laravel 5.7

Your many-to-many relationship requires three tables: abouts, categories, and about_category. You haven't created the about_category table:

Schema::create('about_category', function (Blueprint $table) {
$table->integer('about_id')->unsigned();
$table->integer('category_id')->unsigned();

$table->foreign('about_id')->references('id')->on('abouts');
$table->foreign('category_id')->references('id')->on('categories');
});

Laravel Base table or view not found: 1146 Table

Because of the following method.

public function diversities()
{
return $this->belongsToMany('App\Models\Diversity');
}

You are using belongsToMany which is many-to-many relationship. Since you didn't explicitly defined the table name for middle table, it creates it from the naming convention. It assumes that your middle table is the table of the first one diversity + _ and item.

You can use client_diversity as the second parameter to diversities method.

As it is stated in the documentation

As mentioned previously, to determine the table name of the relationship's joining table, Eloquent will join the two related model names in alphabetical order. However, you are free to override this convention. You may do so by passing a second argument to the belongsToMany method:



Related Topics



Leave a reply



Submit