4

Im using Laravel framework and it gives an error with the DB

Error message:

[2016-04-25 06:07:34] local.ERROR: exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1364 Field 'remarks' doesn't have a default value' in ...

The field 'remarks' has a default value of 'None' set in PHPMyAdmin. I dont understand why does it gives an error when it has a default value set. I believe that 'None' is a string value so it's not like a NULL value.

$aId = DB::table('attachments')->insertGetId([ 'document_type_code'=>$document_id, 'report_no'=>'report '.$document_id, 
'file_attachment_link'=>$filepath, 'file_attachment_upload'=>$file->getClientOriginalName(), 'uploaded_at'=> $now, 'uploaded_by' => 1, 
//Auth::user()->id 'version_number' => 1, ]);
3
  • 1
    Please show your code!! Commented Apr 25, 2016 at 6:17
  • $aId = DB::table('attachments')->insertGetId([ 'document_type_code'=>$document_id, 'report_no'=>'report '.$document_id, 'file_attachment_link'=>$filepath, 'file_attachment_upload'=>$file->getClientOriginalName(), 'uploaded_at'=> $now, 'uploaded_by' => 1, //Auth::user()->id 'version_number' => 1, ]); Commented Apr 25, 2016 at 6:23
  • Edit your question and paste your code there Commented Apr 25, 2016 at 6:24

2 Answers 2

1

None is not a default string value. It means that there is no default value set.

You can either pass a value in your INSERT statement or alter the table to actually hold a default value for the column.

You can use this sql statement to alter the table

ALTER TABLE attachments MODIFY COLUMN `remarks` VARCHAR(255) DEFAULT 'something';

Or do it from PhpMyAdmin

Sign up to request clarification or add additional context in comments.

1 Comment

I am getting same error. Please help me- stackoverflow.com/questions/46322806/…
1

Don't edit the tables directly. You have your model for that. Generate a new migration and set you field to be nullable:

$table->string('name', 50)->nullable();

and then php artisan migrate

1 Comment

I am getting Same error. Please help me-stackoverflow.com/questions/46322806/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.