我正试图在数据库的“posts”列中添加新注释,但出现以下错误[QueryException],“message”:“SQLSTATE[23000]:完整性约束冲突:1048列“description”不能为空。
尽管我在表格里填了描述栏!!!
ajax:
$('#frcoments').on('submit',function (e) {
e.preventDefault();
var description = $('#description').val();
var da = new Date();
var dat = da.toLocaleDateString();
var ti = new Date();
var tim = ti.toLocaleTimeString();
var dat_tim = dat.concat(" ",tim);
$.ajax({
type: 'post',
dataType: 'json',
data: {description: description},
success: function( data ) {
info.hide().find('ul').empty();
if(!data.errors){
$("#respod").append('<div class="fils-body"><p style="margin-bottom:3px; font-size:12px">'+data['description']+'</p></div>');
document.getElementById("description").value="";
$("#description").focus();
}else{
$.each(data.errors, function(index, error) {
info.find('ul').append('<li>'+error+'</li>');
});
info.slideDown();
$("#description").focus();
}
},
error:function(){}
});
// }
});
view:
{!! Form::open(array('url'=> $jour->users_id.'/journal', 'method'=>'POST', 'id'=>'frcoments')) !!}
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
{!! Form::text('description', null, ['class' =>'form-control', 'style'=>'border-radius: 0']) !!}
</div>
<div class="form-group">
{!! Form::submit('Publier', array('class'=>'btn btn-danger')) !!}
</div>
{!! Form::close() !!}
controller:
if($request->ajax()){
$coment=Input::get('description');
$Coments= new \App\Post;
$Coments->journals_id = '5';
$Coments->date = \Carbon\Carbon::now();
$Coments->aimer='0';
$Coments->naimer='0';
$Coments->description=$coment;
$Coments->save();
return \Response::json($Coments);
}else{
return 'no';
}
最佳答案
您试图在“name”字段中插入一个空值,但尚未将此列定义为可空。
尝试在迁移中使用“name”定义中的->nullable()
方法。查看此链接https://laravel.com/docs/5.0/schema#adding-columns