Laravel-4.1 时间戳()问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21645475/
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-09-14 08:59:57  来源:igfitidea点击:

Laravel-4.1 timestamps() issue

phplaravellaravel-4

提问by zarpio

This is my table structure

这是我的表结构

    public function up()
    {
        Schema::create('tags', function($table){
            $table->increments('tagId');
            $table->string('tagName');
            $table->timestamp('tagCreated');
        });
    }

When I store a record, it says me column not found. Even I am not using "$table->timestamps();"

当我存储记录时,它说我没有找到列。即使我没有使用“$table->timestamps();”

Please help how to fix it? Is it necessary to store "timestamps()" for every table?

请帮助如何解决它?是否有必要为每个表存储“时间戳()”?

Illuminate \ Database \ QueryException

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'updated_at' in 'field list' (SQL: insert into tags(tagName, tagCreated, updated_at, created_at) values (test, 2014-02-08 16:19:04, 2014-02-08 11:19:09, 2014-02-08 11:19:09))

照亮\数据库\查询异常

SQLSTATE [42S22]:未发现柱:1054未知列'的updated_at'在'字段列表'(SQL:插入到tagstagNametagCreatedupdated_atcreated_at)的值(测试,16点19分04秒2014年2月8日,2014年2月8日11:19:09, 2014-02-08 11:19:09))

回答by LittlePip

You need to tell the model that you're not using timestamps by adding

您需要通过添加来告诉模型您没有使用时间戳

 public $timestamps = false;

To your model class. You can read more about them here: http://laravel.com/docs/eloquent#timestamps

到你的模型课。您可以在此处阅读有关它们的更多信息:http: //laravel.com/docs/eloquent#timestamps

Note that the scheme migrations is just for the database - not the model. There is no way for Laravel to know that you didn't invoke "timestamps" in the migration. You need to specify the relationship between the model and the schema in your model classes - while the migrations simply worry about the database directly.

请注意,方案迁移仅适用于数据库 - 而不是模型。Laravel 无法知道您没有在迁移中调用“时间戳”。您需要在模型类中指定模型和模式之间的关系 - 而迁移只是直接担心数据库。