laravel SQLSTATE 错误插入错误table?
laravel SQLSTATE error inserting in wrong table?
我是 laravel 的初学者,现在我在插入数据库时遇到问题。错误指出
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'myhris_db.description' doesn't exist.
为什么选择 table 名称描述?我有我的 table 名字扣除。请查看我的代码:
这是我的模型:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Deduction extends Model
{
protected $table = 'deduction';
protected $primaryKey = 'deduction_id';
}
这是我的控制器:
public function store(Request $request)
{
$validator = Validator::make($request->all(),
[
'description' => 'required|max:255|unique:description',
'note' => 'required',
'status' => 'required',
],
[
'description.unique' => trans('auth.DescriptionTaken'),
'description.required' => trans('auth.DescriptionRequired'),
'description.max' => trans('auth.DescriptionMax'),
'note.required' => trans('auth.NoteRequired'),
'status.required' => trans('auth.StatusRequired'),
]
);
if ($validator->fails()) {
return back()->withErrors($validator)->withInput();
}
$deduction = Deduction::create([
'description' => $request->input('description'),
'note' => $request->input('note'),
'status' => $request->input('status'),
]);
return redirect('admin-deduction')->with('success', trans('usersmanagement.createSuccess'));
}
'description' => 'required|max:255|unique:description'
unique:description
表示需要在 table description
中唯一的原始数据
我是 laravel 的初学者,现在我在插入数据库时遇到问题。错误指出
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'myhris_db.description' doesn't exist.
为什么选择 table 名称描述?我有我的 table 名字扣除。请查看我的代码:
这是我的模型:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Deduction extends Model
{
protected $table = 'deduction';
protected $primaryKey = 'deduction_id';
}
这是我的控制器:
public function store(Request $request)
{
$validator = Validator::make($request->all(),
[
'description' => 'required|max:255|unique:description',
'note' => 'required',
'status' => 'required',
],
[
'description.unique' => trans('auth.DescriptionTaken'),
'description.required' => trans('auth.DescriptionRequired'),
'description.max' => trans('auth.DescriptionMax'),
'note.required' => trans('auth.NoteRequired'),
'status.required' => trans('auth.StatusRequired'),
]
);
if ($validator->fails()) {
return back()->withErrors($validator)->withInput();
}
$deduction = Deduction::create([
'description' => $request->input('description'),
'note' => $request->input('note'),
'status' => $request->input('status'),
]);
return redirect('admin-deduction')->with('success', trans('usersmanagement.createSuccess'));
}
'description' => 'required|max:255|unique:description'
unique:description
表示需要在 table description