Lumen define table 名称不起作用

Lumen define table name does not work

我有一个供几个人使用的数据库。所以碰巧我更改了 类 的名称,但 table 的名称相同。所以我使用的是:

class Device extends Model
{
    public $timestamps = false;

    protected $table = 'fota_devices';
}

但我收到错误消息:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'database-fota.devices' doesn't exist (SQL: select count(*) as aggregate from devices where ....)

table 名称似乎没有分配。 我尝试 php artisan cache:clearcomposer dump-autoload。 还是不行。

编辑:控制器代码

class DeviceController extends Controller
{
public function store(Request $request) {
    $i = 1;
    $data_array = json_decode($request->data,true);
    foreach ($data_array as $data) {
        $validator =Validator ::make($data,[
            ..
            ]
        );

        if (! $validator->fails()) {
            $device = new Device;
            $device->create([
            ...
            ]);
            $response[$i]['status'] = "Success";
        }
        else {
            $response[$i]['status'] = "Failed";
            $response[$i]["errors"] = $validator->errors()->all();
        }
        $response[$i]['data'] = $data;
        $i++;
    }
    return new Response(200);
}
}

一旦你检查了 table 名称中的模型和 table 名称中的 MySQL 数据库是相同的,或者 different.Because 你在表格名称中的模型如下所示,无论何时您 运行 查询 table 名称与下面不同。

protected $table = 'fota_devices';


Query :- select count(*) as aggregate from devices where ....)

以上两个 table 是不同的。

您的 table 名称与 fota_devicesdevices.

不同