【问题标题】:Php Artisan tinker wont save updated entry in tablePhp Artisan tinker 不会在表中保存更新的条目
【发布时间】:2015-03-16 19:32:58
【问题描述】:

PHP LARAVEL 5. 所以我想从工作表中找到状态为零的最新项目。现在我只想尝试更新工作类型。但它会提取我想要更新的正确项目,如下所示。我尝试更新并保存并收到此错误。

>>> $job=\App\Job::orderBy('created_at', 'desc')->where('status', 0)->where('created_at', '>', '$current_dt')->first()


=> <App\Job #000000006ea292f40000000026d13dc7> {
   job_id: "4",
   job_hash: "ujshdujsh",
   job_type: "ujshdujsh",
   parameters: "",
   created_at: "2015-03-16 17:41:07",
   updated_at: "2015-03-16 17:41:07",
   available_ts: "0000-00-00 00:00:00",
   status: "0"
   }

>>> $job->job_type='updated'
=> "updated"

>>> $job->save();
Illuminate\Database\QueryException with message 'SQLSTATE[42S22]: Column    not found: 1054 Unknown column 'id' in 'where clause' 
(SQL: update `jobs` set `job_type` = updated, `updated_at` = 2015-03-16 17:58:38 where `id` is null)'
>>> 

【问题讨论】:

    标签: eloquent laravel-5


    【解决方案1】:

    http://laravel.com/docs/5.0/eloquent#basic-usage

    protected $primaryKey = 'job_id';
    

    【讨论】:

      猜你喜欢
      • 2019-10-24
      • 1970-01-01
      • 2021-02-27
      • 2018-03-29
      • 2020-09-30
      • 1970-01-01
      • 2016-02-15
      • 2020-03-23
      • 2020-03-05
      相关资源
      最近更新 更多