gpt4 book ai didi

php - SQLSTATE[23000] : Integrity constraint violation: 1048 Column 'description' cannot be null (SQL: insert into) in laravel

转载 作者:行者123 更新时间:2023-11-29 03:24:16 26 4
gpt4 key购买 nike

我正在尝试将新评论添加到我的数据库中的“帖子”列中,但是我收到此错误 [QueryException","message":"SQLSTATE[23000]: Integrity constraint violation: 1048 Column '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';
}

最佳答案

您正试图在“名称”字段中插入空值,但您尚未将此列定义为可为空。尝试在迁移的“名称”定义中使用 ->nullable() 方法。看看这个链接 https://laravel.com/docs/5.0/schema#adding-columns

关于php - SQLSTATE[23000] : Integrity constraint violation: 1048 Column 'description' cannot be null (SQL: insert into) in laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38933579/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com