1

I have been trying to update a document using laravel ORM but getting exception stating a unknown column updated_at.

This column is not in database table, and neither have I mentioned in the query.

$foo = ProductMatchUnmatchHistory::where('product_match_unmatches_id', $pmu->id) ->update(['is_latest'=>0]); 

ProductMatchUnmatchHistory model:

protected $fillable = [ 'product_match_unmatches_id', 'human_verdict', 'ai_result', 'updated_on', 'updated_by', 'is_latest' ]; 

The table has the same columns as in $fillable array, with additional id primary key.

Here's the exception message:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'updated_at' in 'field list' (SQL: update `product_match_unmatch_histories` set `is_latest` = 0, `updated_at` = 2019-11-20 12:20:02 where `product_match_unmatches_id` = 1759) 

I have no clue from where the updated_at column is added to the query.

0

4 Answers 4

4

If you don't want to use the updated_at and created_at fields from Laravel's Eloquent models, edit your ProductMatchUnmatchHistory.php model and set $timestamps = false.

class ProductMatchUnmatchHistory extends Model { //.... $timestamps = false; //.... } 

Additional Info

Laravel Models automatically set a created_at field when an entry is created and update the updated_at column when you do any changes to a row. This is handled through the $timestamps field on the model. If set to true, which is default, laravel will assume that your models have created_at and updated_at fields.

In most cases this is pretty helpful. You can easily add these fields in your migration by just adding $table->timestamps();.

See https://laravel.com/docs/5.8/eloquent#eloquent-model-conventions (under Timestamps)

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

Comments

1

please change

you must define table name

protected $table = 'your table name'; protected $fillable = [ 'product_match_unmatches_id', 'human_verdict', 'ai_result', 'updated_on', 'updated_by', 'is_latest' ]; $timestamps = false; 

2 Comments

$timestamps=false worked for me.
Ok great please select this answer as Helpful thank you.@Azima
0

First please check in your table updated_at exist? because sql error say column not found

1 Comment

no.. there's no updated_at. Is this a mandatory field?
0

@Azima you should added the column in your table otherwise you will get this error, because eloquent updating that column and its not present in table or you can $timestamps=false in your Model

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.