php 未找到列:1054 未知列 Laravel

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27638487/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:27:03  来源:igfitidea点击:

Column not found: 1054 Unknown column laravel

phpmysqllaravel

提问by Greatone

so i trying to make a form with laravel but other than in new version they removed form ! but i can get this running

所以我试图用 laravel 制作一个表格,但除了新版本之外,他们删除了表格!但我可以让它运行

so here is is :

所以这里是:

Route::post('/register', function()
{
    $user = new User;
    $user-> u_n = Input::get('u_n');
    $user->save();
    return View::make('thanks')->with('theEmail',$theEmail);
});

and my blade :

还有我的刀片:

{{Form::open(array('url'=>'register'))}}

username : {{Form::label('u_n', 'E-Mail Address');}}
{{Form::text('u_n');}}
{{Form::submit('');}}

u_n is name of my mysql data base field and this is the actual error :

u_n 是我的 mysql 数据库字段的名称,这是实际错误:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'updated_at' in 'field list' (SQL: insert into `users` (`u_n`, `updated_at`, `created_at`) values (sepehr, 2014-12-24 14:32:55, 2014-12-24 14:32:55))

回答by lukasgeiter

This is happens because Laravel assumes you want to use the updated_atand created_attimestamps for your models. So it also assumes they exist in the database. You can either create the two columns or disable timestamps for your model by adding

发生这种情况是因为 Laravel 假设您要为模型使用updated_atcreated_at时间戳。所以它还假设它们存在于数据库中。您可以通过添加创建两列或禁用模型的时间戳

public $timestamps = false;

Laravel Docs

Laravel 文档

By the way: If you're using migrations, adding the timestamp columns is a breeze.

顺便说一句:如果您使用迁移,添加时间戳列是轻而易举的。

Schema::table('table_name', function(Blueprint $table){
    $table->timestamps();
}

回答by XFaramir

This did the trick for me.

这对我有用。

     $table->timestamp('created_at')->nullable();
        $table->timestamp('updated_at')->nullable();:

Then reset your migrations

然后重置您的迁移

    php artisan migrate:reset
    php artisan migrate