LoginSignup
2
1

More than 3 years have passed since last update.

エラー:General error: 1 table posts has no column named updated_at

Last updated at Posted at 2020-02-02

エラー

phpでsaveをしようとしたら、下記のエラーが表示
Image from Gyazo

>>> $post->save();
Illuminate/Database/QueryException with message 'SQLSTATE[HY000]: General error: 1 table posts has no column named updated_at (SQL: insert into "posts" ("body", "title", "updated_at", "created_at") values (body 1, title 1, 2020-02-02 14:58:15, 2020-02-02 14:58:15))'

対策

$timestamps無効にすれば改善される。
そのモデルに下記を追記する

public $timestamps = false;
モデル
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    public $timestamps = false;
}

確認

>>> $post = new App\Post();
=> App\Post {#2894}
>>> $post->title = 'title 1';
=> "title 1"
>>> $post->body = 'body 1';
=> "body 1"
>>> $post->save();
=> true
>>> 

trueが表示されており成功している

2
1
0

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
2
1