LoginSignup
0
0

More than 3 years have passed since last update.

【Laravel】タイムスタンプがないテーブルを更新する

Posted at

環境

・windows10
・PHP(7.3.6)
・Laravel(5.8.27)
・MariaDB

問題

インスタンス作成
$post = new App\post;
=> App\Post {#2960}

レコード挿入
$post->title = 'title 1';
=> "title 1"
$post->body = 'body 1';
=> "body 1"

そしてsaveメソッド
$post->save();

すると
Column not found: 1054 Unknown column ‘updated_at’ in ‘field list’
というエラー表示

解決

こちらのサイトが参考になりました
【Laravel】タイムスタンプがないテーブルを更新(保存)する方法

上記エラーはupdated_atカラムとやらがないのが原因なので
日付情報を記録するタイムスタンプ機能を無効にすればいいらしい

$post->timestamps = false;
=> false
$post->save();
=> true

成功

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0