Skip to content

SQLSTATE[HY000]: General error: 1364 Field 'disk_name' doesn't have a default value #5270

@aniket-magadum

Description

@aniket-magadum
  • OctoberCMS Build: ### 468
  • PHP Version: 7.2.19
  • Database Engine: InnoDB
  • Plugins Installed: RainLab.User

Description:

I have created a component inside for my custom plugin and I am trying to attach one resume to the user model.

Plugin.php in the register method I have placed the following code.

$user->attachOne['resume'] = SystemFile::class;

This is the partial file

{% set user = __SELF__.user %}

<div class="profile-update">
    <h2>Additional Information</h2>
    {{ form_ajax(__SELF__~'::onUpdate',{files:true}) }}
    
    {% if user.resume %}
    <p>Uploaded Resume : <a href="{{ user.resume.getPath() }}">{{ user.resume.getFileName() }}</a> (You can
        upload a new resume below)</p>
    {% endif %}

    <div class="form-group">
        <label for="resume">Resume</label>
        <input type="file" class="form-control-file" name="resume" />
        <span class="text-danger" data-validate-for="resume"></span>
    </div>

    <button type="submit" class="btn btn-primary"> Save </button>
    {{ form_close()}}
</div>

I am uploading the file via AjaxHandler onUpdate(). Here is the code in the method.

public function onUpdate()
{
     if (Input::hasFile('resume')) {
           $resume = Input::file('resume');
           $this->user->resume = $resume;
      }
      $this->user->save();
      return Redirect::refresh();
}

When the above code runs it throws an Exception as follows

"SQLSTATE[HY000]: General error: 1364 Field 'disk_name' doesn't have a default value (SQL: insert into `system_files` (`is_public`, `field`, `attachment_id`, `attachment_type`, `updated_at`, `created_at`) values (1, resume, 1, RainLab\User\Models\User, 2020-09-09 04:43:36, 2020-09-09 04:43:36))" on line 664 of C:\laragon\www\oc-recruitment\vendor\laravel\framework\src\Illuminate\Database\Connection.php

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions