LARAVEL - 未找到基表或视图:1146 表不存在(SQL: select * from )

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47858924/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:07:21  来源:igfitidea点击:

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

phplaravellaravel-5model

提问by alexandre1985

I have a Mysql database minho.winand a table called utilizadores.

我有一个 Mysql 数据库minho.win和一个名为utilizadores.

I created a model class php artisan make:model Utilizador

我创建了一个模型类 php artisan make:model Utilizador

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

当我这样做php artisan tinker然后App\Utilizador::all()我得到这个错误:

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)'

Illuminate\Database\QueryException 消息为“SQLSTATE[42S02]:未找到基表或视图:1146 表 'minho.win.utilizadors' 不存在(SQL:select * from utilizadors)”

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

为什么要寻找名为 的表utilizadors?我怎样才能让它寻找合适的表 - utilizadores

回答by Mathew Tinsley

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

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

回答by Telemarque Ernest

so you have to protect your table in you Model something like that:in Your Model

所以你必须在你的模型中保护你的桌子:在你的模型中

protected $table = "utilizadores";

put your field's name in this array, it will seem like that:

将您的字段名称放在此数组中,它看起来像这样:

protected $filliable  = [
"id", 
""
];