Laravel未知列'updated_at' [英] Laravel Unknown Column 'updated_at'

查看:349
本文介绍了Laravel未知列'updated_at'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用Laravel,却遇到以下错误:

I've just started with Laravel and I get the following error:

未知列"updated_at"插入gebruikers(naam,wachtwoord, Updated_at,created_at)

Unknown column 'updated_at' insert into gebruikers (naam, wachtwoord, updated_at, created_at)

我知道错误是来自于迁移表时的时间戳列,但我没有使用updated_at字段.我遵循Laravel教程时曾经使用它,但是现在我正在制作(或尝试制作)自己的东西.即使我不使用时间戳,我也会收到此错误.我似乎找不到使用它的地方.这是代码:

I know the error is from the timestamp column when you migrate a table but I'm not using the updated_at field. I used to use it when I followed the Laravel tutorial but now that I am making (or attempting to make) my own stuff. I get this error even though I don't use timestamps. I can't seem to find the place where it's being used. This is the code:

控制器

public function created()
{
    if (!User::isValidRegister(Input::all())) {
        return Redirect::back()->withInput()->withErrors(User::$errors);
    }

    // Register the new user or whatever.
    $user = new User;
    $user->naam = Input::get('naam');
    $user->wachtwoord = Hash::make(Input::get('password'));
    $user->save();

    return Redirect::to('/users');
}

路线

Route::get('created', 'UserController@created');

模型

public static $rules_register = [
    'naam' => 'unique:gebruikers,naam'
];

public static $errors;
protected $table = 'gebruikers';

public static function isValidRegister($data)
{
    $validation = Validator::make($data, static::$rules_register);

    if ($validation->passes()) {
        return true;
    }

    static::$errors = $validation->messages();

    return false;
}

我一定会忘记某事...我在这里做错了什么?

I must be forgetting something... What am I doing wrong here?

推荐答案

在模型中,编写以下代码;

In the model, write the below code;

public $timestamps = false;

这行得通.

说明:默认情况下,laravel将期望created_at&表中的Updated_at列. 通过将其设置为false,它将覆盖默认设置.

Explanation : By default laravel will expect created_at & updated_at column in your table. By making it to false it will override the default setting.

这篇关于Laravel未知列'updated_at'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆