[英]SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'status' cannot be null
[英]SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'cne' cannot be null
保存數據時出現錯誤。
Illuminate\Database\QueryException
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'cne' cannot be null (SQL: insert into `students` (`cne`, `firstName`, `secondName`, `age`, `speciality`, `updated_at`, `created_at`) values (?, ?, ?, ?, ?, 2020-04-03 20:47:34, 2020-04-03 20:47:34))
我想知道我能做些什么來解決這個問題。
路線
Route::get('/',"StudentController@index") ;
Route::get('/edit/{id}',"StudentController@edit") ;
Route::get('/show/{id}',"StudentController@show") ;
Route::get('/create',"StudentController@create") ;
Route::get('/store',"StudentController@store") ;
Route::get('/update/{id}',"StudentController@update") ;
Controller
public function store(Request $request )
{
$student = new Student() ;
$student->cne = $request->input('cne') ;
$student->firstName = $request->input('firstName') ;
$student->secondName = $request->input('secondName') ;
$student->age = $request->input('age') ;
$student->speciality = $request->input('speciality') ;
$student->save() ;
return redirect('/') ;
//
}
HTML
@if($layout == 'index')
<div class="container-fluid">
<div class="row">
<selctio class="col">
@include("studentslist")
</selction>
<selction class="col"></selction>
</div>
</div>
@elseif($layout == 'create')
<div class="container-fluid" id="create-form">
<div class="row">
<selctio class="col">
@include("studentslist")
</selction>
<selction class="col">
<form action="{{ url('/store') }}" method="POST" >
@csrf
<div class="form-group">
<label>CNE</label>
<input name="cne" id="cne" type="text" class="form-control" placeholder="Enter cne">
</div>
<div class="form-group">
<label>First Name</label>
<input name="firstName" id="firstName" type="text" class="form-control" placeholder="Enter the first name">
</div>
<div class="form-group">
<label>second Name</label>
<input name="secondName" type="text" class="form-control" placeholder="Enter second name">
</div>
<div class="form-group">
<label>Age</label>
<input name="age" type="text" class="form-control" placeholder="Enter the Age">
</div>
<div class="form-group">
<label>Speciality</label>
<input name="speciality" type="text" class="form-control" placeholder="Enter Sepeciality">
</div>
<input type="submit" class="btn btn-info" value="Save">
<input type="reset" class="btn btn-warning" value="Reset">
</form>
</selction>
</div>
</div>
@elseif($layout == 'show')
<div class="container-fluid">
<div class="row">
<selctio class="col">
@include("studentslist")
</selction>
<selction class="col"></selction>
</div>
</div>
@elseif($layout == 'edit')
<div class="container-fluid">
<div class="row">
<section class="col-md-7">
@include("studentslist")
</section>
<section class="col-md-5">
</section>
</div>
</div>
@endif
當列..不能為 null 時,會觸發“1048 列”不能為空”錯誤。
你應該看看你的遷移文件。 像這樣添加可為空的方法:
$table->string('cne')->nullable();
如果您不想重寫遷移,則需要使用類似的東西:
$table->string('cne')->nullable()->change();
此外,更改 Route 文件,以便 store 路由使用 post 方法:
Route::post('/store',"StudentController@store") ;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.