SQLSTATE[HY000]:一般错误:1364 字段
Posted
技术标签:
【中文标题】SQLSTATE[HY000]:一般错误:1364 字段【英文标题】:SQLSTATE[HY000]: General error: 1364 Field 【发布时间】:2018-08-02 05:20:37 【问题描述】:public function index()
$students = Student::all()->toArray();
return view('student.index', compact('students'));
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
return view('student.create');//
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
$this->validate($request, [
'first_name' => 'required',
'last_name' => 'required',
'Age' => 'required',
'Address' => 'required',
'Grade_Level' => 'required',
'mothers_first_name' => 'required',
'mothers_last_name' => 'required',
'mothers_age' => 'required',
'fathers_first_name' => 'required',
'fathers_last_name' => 'required',
'fathers_age' => 'required'
]);
$student = new Student([
'first_name' => $request->get('first_name'),
'last_name' => $request->get('last_name'),
'Age' => $request->get('Age'),
'Address' => $request->get('Address'),
'Grade_Level' => $request->get('Grade_Level'),
'mothers_first_name' => $request->get('mothers_first_name'),
'mothers_last_name' => $request->get('mothers_last_name'),
'mothers_age' => $request->get('mothers_age'),
'fathers_first_name' => $request->get('fathers_first_name'),
'fathers_last_name' => $request->get('fathers_last_name'),
'fathers_age' => $request->get('fathers_age')
]);
$student->save();
return redirect()->route('student.index')->with('success', 'New teacher data successfully added');
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
//
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
$student = Student::find($id);
return view('student.edit', compact('student', 'id'));
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
$this->validate($request, [
'first_name' => 'required',
'last_name' => 'required',
'Age' => 'required',
'Address' => 'required',
'Grade_Level' => 'required'
]);
$student = Student::find($id);
$student->first_name = $request->get('first_name');
$student->last_name = $request->get('last_name');
$student->Age = $request->get('Age');
$student->Address = $request->get('Address');
$student->Grade_Level = $request->get('Grade_Level');
$student->save();
return redirect()->route('student.index')->with('success', 'Student data successfully updated');
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
$student = Student::find($id);
$student->delete();
return redirect()->route('student.index')->with('success', 'Data successfully deleted');
这是我的控制器,我不知道为什么会出错,我还有其他具有相同功能的控制器,但它工作正常。我最近刚刚添加了这个母亲的名字、年龄等部分,但在它只是名字、年龄地址等之前它工作正常,但是在我添加更多可填充区域之后,我得到了这个错误
and this is the error im getting
<div class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert">×</button>
<ul>
@foreach($errors->all() as $error)
<li>$error</li>
@endforeach
</ul>
</div>
@endif
@if(\Session::has('success'))
<div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert">×</button>
<p><strong>\Session::get('success')</strong></p>
</div>
@endif
<div class="carousel">
<div class="carousel-inner">
<img class="data-img" src="asset('img/adddata.png')">
</div>
</div>
<div class="container student-create">
<div class="students-info">
<h3>Student's Personal Info</h3>
<form method="post" action="url('student')">
csrf_field()
<div class="form-group">
<div class="col-sm">
<label for="Inputfirstname">First Name</label>
<input type="text" class="form-control" name="first_name" placeholder="Enter First Name">
</div>
<div class="col-sm">
<label for="Inputlastname">Last Name</label>
<input type="text" class="form-control" name="last_name" placeholder="Enter Last Name">
</div>
<div class="col-sm">
<label for="Inputlastname">Age</label>
<input type="number" class="form-control" name="Age" placeholder="Enter Last Name">
</div>
</div>
<div class="form-group">
<div class="col-sm">
<label for="InputAddress">Address</label>
<input type="text" class="form-control" name="Address" placeholder="Enter Address">
</div>
<div class="col-sm">
<label for="InputAddress">Grade Level/College Level</label>
<select class="custom-select" name="Grade_Level">
<option selected="">Select Grade Level</option>
<option>Day Care 1</option>
<option>Day Care 2</option>
<option>Kinder Garten 1</option>
<option>Kinder Garten 2</option>
<option>Elementary 1</option>
<option>Elementary 2</option>
<option>Elementary 3</option>
<option>Elementary 4</option>
<option>Elementary 5</option>
<option>Elementary 6</option>
<option>Junior Highschool 1</option>
<option>Junior Highschool 2</option>
<option>Junior Highschool 3</option>
<option>Junior Highschool 4</option>
<option>Senior Highschool 1</option>
<option>Senior Highschool 2</option>
<option>College Level Information Technology 1</option>
<option>College Level Information Technology 2</option>
<option>College Level Information Technology 3</option>
<option>College Level Information Technology 4</option>
</select>
</div>
</div>
<h3>Student's Parents Info</h3>
<div class="form-group">
<div class="col-sm">
<label for="Inputfirstname">Mothers First Name</label>
<input type="text" class="form-control" name="mothers_first_name" placeholder="Enter First Name">
</div>
<div class="col-sm">
<label for="Inputfirstname">Mothers Last Name</label>
<input type="text" class="form-control" name="mothers_last_name" placeholder="Enter Last Name">
</div>
<div class="col-sm">
<label for="Inputfirstname">Mothers Age</label>
<input type="number" class="form-control" name="mothers_age" placeholder="Enter Age">
</div>
</div>
<div class="form-group">
<div class="col-sm">
<label for="Inputfirstname">Fathers First Name</label>
<input type="text" class="form-control" name="fathers_first_name" placeholder="Enter First Name">
</div>
<div class="col-sm">
<label for="Inputfirstname">Fathers Last Name</label>
<input type="text" class="form-control" name="fathers_last_name" placeholder="Enter Last Name">
</div>
<div class="col-sm">
<label for="Inputfirstname">Fathers Age</label>
<input type="number" class="form-control" name="fathers_age" placeholder="Enter Age">
</div>
</div>
<div class="form-group submit">
<button type="button submit" class="btn btn-success">
<i class="fas fa-check"></i> Submit Data
</button>
</div>
</form>
</div>
表结构
Student Model
我希望你能帮助我并提前感谢
【问题讨论】:
可以添加学生模型和表结构吗? 我编辑了我的问题并添加了表格结构 您需要在 'fathers_age' 字段中发送数据,或者您可以将其设为可空,以免出错。 在学生模型中,您需要将 'fathers_Age' 更改为 'fathers_age'.. 区分大小写。 @Ankit 在我的情况下,它只是区分大小写的一个是我试图纠正的问题,现在它工作正常谢谢你的回答 KUDOS 【参考方案1】:您可以将fathers_age
字段名称更改为fathers_Age
。因为您在数据库中使用了fathers_Age
字段。
【讨论】:
@KurtPino:如果我的回答对您有用,请接受我的回答并投票赞成我的回答以上是关于SQLSTATE[HY000]:一般错误:1364 字段的主要内容,如果未能解决你的问题,请参考以下文章
SQLSTATE [HY000]:一般错误:1364 字段“标题”没有默认值
SQLSTATE [HY000]:一般错误:1364 字段 'uID' 没有默认值
SQLSTATE [HY000]:一般错误:1364 字段“author_id”没有默认值
SQLSTATE[HY000]:一般错误:1364(Laravel 用 eloquent 创建新行)