Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel-4.1 timestamps() issue

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();"

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))

like image 833
zarpio Avatar asked Feb 08 '14 11:02

zarpio


1 Answers

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

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.

like image 99
LittlePip Avatar answered Sep 21 '22 14:09

LittlePip