Framework: [5.5] Problem with updated_at, When update data or deleted data use SoftDeletes.

Created on 19 Sep 2017  路  7Comments  路  Source: laravel/framework

  • Laravel Version: 5.5.4
  • PHP Version: 7.1.8
  • Database Driver & Version: MySQL 5.7.18

Description:

I got error when my Model has no updated_at, Then update data or deleted data use SoftDeletes.

I use this code for set updated_at.

   public function setUpdatedAt($value)
  {
    return $this;
  }

App\Model::destroy(569) always got error.

Illuminate\Database\QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'updated_at' in 'field list' (SQL: update `models` set `delete
d_at` = 2017-09-19 18:04:19, `updated_at` = 2017-09-19 18:04:19 where `id` = 569)'

But with Model::create($data); it's fine.

Steps To Reproduce:

<?php namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Model extends Model
{
    use SoftDeletes;

  protected $fillable = [
    'data'
  ];

  /**
   * Set the value of the "updated at" attribute.
   *
   * @param  mixed  $value
   * @return $this
   */
  public function setUpdatedAt($value)
  {
    return $this;
  }
}

Most helpful comment

update your model with this:
public $timestamps = false;

All 7 comments

Similar to #20901

@Dylan-DPC Oh, Got it. Thanks

    const UPDATED_AT = null;

    /**
    * Set the value of the "updated at" attribute.
    *
    * @param  mixed  $value
    * @return $this
    */
    public function setUpdatedAt($value)
    {
        return $this;
    }

I'm not sure 100%, but setUpdatedAt method is not required when UPDATED_AT = null constant is added.

@a-komarev Not with 5.5 #20948

update your model with this:
public $timestamps = false;

public $timestamps = false; worked for me! thanks

WORKED for me !!!!!
public $timestamps = false;

thanks @Nitish27

Was this page helpful?
0 / 5 - 0 ratings

Related issues

progmars picture progmars  路  3Comments

felixsanz picture felixsanz  路  3Comments

shopblocks picture shopblocks  路  3Comments

lzp819739483 picture lzp819739483  路  3Comments

PhiloNL picture PhiloNL  路  3Comments