SQLSTATE [23000]:完整性约束违规:1048列' job_description'不能无效
sqlState [23000]:完整性约束违规:1048列“ job_description'不能为null(sql:insert in job (
job_title
,job_description ,<代码>文件
,Note
)valut(eee,?,user.jpg,kjl))
迁移
{
Schema::create('jobs', function (Blueprint $table) {
$table->id();
$table->String('job_title');
$table->String('job_description');
$table->String('file');
$table->String('note');
$table->timestamps();
});
}
模型
{
use HasFactory;
protected $fillable = [
'job_title',
'job_description',
'file',
'note',
];
控制器
Job::insert([
'job_title'=>$request->job_title,
'job_description'=>$request->job_description,
'file'=>$request->file,
'note'=>$request->note
]);
return Redirect()->back()->with('success','Job added successfully');
}
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'job_description' cannot be null (SQL: insert into jobs
(job_title
, job_description
, file
, note
) values (EEE, ?, user.JPG, KJL))
migration
{
Schema::create('jobs', function (Blueprint $table) {
$table->id();
$table->String('job_title');
$table->String('job_description');
$table->String('file');
$table->String('note');
$table->timestamps();
});
}
model
{
use HasFactory;
protected $fillable = [
'job_title',
'job_description',
'file',
'note',
];
controller
Job::insert([
'job_title'=>$request->job_title,
'job_description'=>$request->job_description,
'file'=>$request->file,
'note'=>$request->note
]);
return Redirect()->back()->with('success','Job added successfully');
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
数据库中的列Job_description设置为非零约束。以及尝试使用$ request-&gt; job_description设置的值。这是这个问题的根本原因。
您可以修改控制器。
为了纠正您可以使用
Input()
为字段提供默认值,The column job_description in the database is set up as NOT NULL constraints. And the value trying to set using $request->job_description with NULL. That is the root cause of this issue.
To rectify you can modify your controller like:
Or provide a default value for fields using
input()
使用
nullable
用于列声明$ table-&gt; string('job_description') - &gt; nullable()
,如果您想将其与null值一起使用。Use
nullable
for column declaration$table->string('job_description')->nullable()
, if you want use it with null value.