Thursday, February 3, 2022

[FIXED] LARAVEL - Base table or view not found: 1146 Table doesn't exist (SQL: select * from )

Issue

I have a Mysql database minho.win and a table called utilizadores.

I created a model class php artisan make:model Utilizador

When I do php artisan tinker and then do App\Utilizador::all() I get this error:

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

Why is it looking for a table named utilizadors? How can I make it look for the right table - utilizadores?


Solution

You can specify the table in your model:

class Utilizador extends Model {
    protected $table = 'utilizadores';
}

https://laravel.com/docs/5.5/eloquent#eloquent-model-conventions



Answered By - Mathew Tinsley

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.