php - SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'invest_id' cannot be null
Get the solution ↓↓↓all
Please help with the above error.
I am trying to post data to the database.
This is the table below :
public function up() {
Schema::create('investment', function (Blueprint $table) {
$table->bigIncrements('id');
$table->decimal('amount');
$table->integer(**'invest_id')->unsigned()**;
$table->integer('reference_id')->unsigned();`
This is the code on the controller
public function confirm(Request $request)
{
$this->validate($request, [
'amount' => 'required|numeric',
'plan_id' => 'required|numeric',
]);
$interest = new Interest();
$interest->invest_id = $request->invest_id;
$interest->user_id = $user->id;
$interest->save();
Answer
Solution:
The easiest way to solve this is set'strict' => false,
in yourconfig/database.php
file. The other way is to add$table->integer('invest_id')->unsigned()->nullable();
to inform the database the value can be null. The default'strict' => true,
option brought me into some issues in the past, as it was introduced in Laravel 5.2.
If you run a brand new application, you could go for the strict option but you'll have to set up your database accordingly.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: videoxxx
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.