duanrong3308 2017-03-16 11:49
浏览 356
已采纳

Laravel - 表不存在

I create a table with php artisan make:migration command. After that i edit the migration file to put the columns and insert standard data. After i run php migrate:referesh command and all good, i go to the database and the table is there with a correct name and data.

In database the table name is rolesStems.

I create a model like this:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class RolesStems extends Model
{
    protected $fillable = ['id', 'value', 'order', 'active','id_stem', 'id_role'];
}

And in my controller i do this:

use App\RolesStems as RolesStem;   
RolesStem::select('value')->where('active', '=', 1)->where('id_stem', '=', 1)->orderBy('id_role', 'asc')->get());

And i have this error:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'dbname.roles_stems' doesn't exist (SQL: select `value` from `roles_stems` where `active` = 1 and `id_stem` = 1 order by `id_role` asc)

It put a unknown table name roles_stems, why?

I do this to other table, the same way, but with this table this happens.

What is the problem?

  • 写回答

3条回答 默认 最新

  • dongya5893 2017-03-16 11:50
    关注

    Because you don't follow Laravel naming conventions, you should define table manually:

    protected $table = 'your_table_name';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?