Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
aniket-magadum opened this issue Sep 9, 2020 · 10 comments

Comments

@aniket-magadum
Copy link
Contributor

  • 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
@damsfx
Copy link
Contributor

damsfx commented Sep 10, 2020

I'm also having trouble with database attachment creation.

  • OctoberCms build : 469
  • Php version : 7.3.11
  • Database Engine: InnoDB
  • No plugins

Either with :

$stripe->logo = plugins_path() .'/acme/myplugin/assets/images/stripe.png';
$stripe->update();

or with :

$stripe->logo()->create(['data' => realpath(__DIR__ . '../../assets/images/stripe.png')]);

@tobias-kuendig
Copy link
Member

@damsfx
Copy link
Contributor

damsfx commented Sep 10, 2020

Reverting back to protected $guarded = []; seems to work in v1.0.469 build.

But it's very strange ... This line has always been like this?
See library/src/Database/Attach/File.php on 9 Jan 2014

@LukeTowers
Copy link
Contributor

@bennothommo can you look into this?

@LukeTowers
Copy link
Contributor

@damsfx @tobias-kuendig @4nik3t is this issue present in v1.1.0?

@damsfx
Copy link
Contributor

damsfx commented Sep 10, 2020

Test this code (from command) with two fresh installs.

$settings  = \Backend\Models\BrandSetting::instance();
$settings->logo = 'plugins/hounddd/toolbox/assets/images/logo.png';
$settings->save();
  • Php version : 7.2.11
  • Database : sqllite
  • No plugins

October 1.1 : Work nice !

in composer.json

"require": {
    "php": ">=7.2",
    "october/rain": "~1.1",
    "october/system": "~1.1",
    "october/backend": "~1.1",
    "october/cms": "~1.1",
    "laravel/framework": "~6.0",
    "wikimedia/composer-merge-plugin": "1.4.1",
    "offline/oc-bootstrapper": "^0.9.1"
},


October 1.0 : Error.

in composer.json

"require": {
    "php": ">=7.0.8",
    "ext-mbstring": "*",
    "ext-openssl": "*",
    "october/rain": "~1.0",
    "october/system": "~1.0",
    "october/backend": "~1.0",
    "october/cms": "~1.0",
    "laravel/framework": "~5.5.40",
    "wikimedia/composer-merge-plugin": "1.4.1",
    "offline/oc-bootstrapper": "^0.9.0"
},

Result this error

In Connection.php line 664:
  SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: system_files.disk_name (SQL: insert into "s
  ystem_files" ("is_public", "field", "attachment_id", "attachment_type", "updated_at", "created_at") values (1, logo, 1, Bac
  kend\Models\BrandSetting, 2020-09-10 23:10:12, 2020-09-10 23:10:12))

In PDOStatement.php line 107:
  SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: system_files.disk_name

In PDOStatement.php line 105:
  SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: system_files.disk_name

If I set protected $guarded = [] in library/src/Database/Attach/File.php it works.

@bennothommo
Copy link
Contributor

@LukeTowers Laravel have backported that security fix from L6 and L7 to L5.5 (the one which made guarded attributes that are not actual database columns no longer work) - laravel/framework#33858

We'll have to add the changes from octobercms/library@6cd6af6 into the 1.0 branch too.

@bennothommo
Copy link
Contributor

All,

If this is preventing you from doing work in the mean time, and you have used Composer, the simple fix is to change the laravel/framework dependency to 5.5.49 in your composer.json to downgrade L5.5, until such a time that we can release a new 1.0 build.

@LukeTowers
Copy link
Contributor

Another simple fix would be to just upgrade to v1.1.0 via composer too :)

@bennothommo
Copy link
Contributor

Fixed by octobercms/library#521 - will be released with the next build of 1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants