数据库查询在laravel上采用错误的表名

时间:2017-04-12 02:40:22

标签: php mysql laravel

QueryException in Connection.php line 647:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydb.posts' 
doesn't exist (SQL: select count(*) as aggregate from `posts` where 
`title` = asdas)

数据库中的表名是post,但它会发布到帖子。

post.php中

class Post extends Model{}

1 个答案:

答案 0 :(得分:0)

因此,如果它不符合laravel默认约定,则需要声明要加载的表。将表设置为类属性:

class Post extends Model
{
    protected $table = 'post';
}