4

My database is working fine with my laravel application but while i was trying to insert data to my database i am facing a error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'updated_at' in 'field list' (SQL: insert into articles (article_head, article_body, updated_at, created_at) values (, , 2016-04-27 18:40:58, 2016-04-27 18:40:58))

My view file

<form method="post" action="{{ url('saving_data') }}">
  {!! csrf_field() !!}
    <div class="form-group">
      <label for="write_heading">Write Heading:</label>
      <textarea class="form-control" rows="3" cols="10" id="write_heading" name="article_head" style="resize: none;"></textarea>
      <label for="write_post">Write Post:</label>
      <textarea class="form-control" rows="15" cols="10" id="write_post" name="article_body" placeholder="write something awesome!!" style="resize: none;"></textarea>
      <br>
      <div class="model-footer">
        <button type='submit' class='btn btn-primary create_button'>Create</button>
        <button type='reset' class='btn btn-default reset_button'>Reset</button>

        <button type="button" class="btn btn-danger close_button" data-dismiss="modal">Close</button>
      </div>

    </div>
</form>

my controller code

class ArticleEditor extends Controller
{
    //insert article to database
    public function insert_article(Request $request) {

      $Article = new article;

      $Article->article_head = $request->article_head;
      $Article->article_body = $request->article_body;

      $Article->save();

      return redirect('/dashboard');
    }
}

Migration file

    public function up()
    {
        Schema::create('articles', function(Blueprint $table)
        {
            $table->increments('article_id');
            $table->string('article_head', 500);
            $table->string('article_body', 10000);
            $table->dateTime('created_on');
        });
    }
2
  • As a note: To format code all you need to do is indent with four spaces or use the {} button to do it for you. Commented Apr 27, 2016 at 18:55
  • ok i will take care of that... Commented Apr 27, 2016 at 19:49

2 Answers 2

6

Your query tries to update timestamps.

You need to use $table->timestamps(); in your migration or add this to your model if you don't want to use them:

public $timestamps = false;

More info about timestamps is here.

Sign up to request clarification or add additional context in comments.

1 Comment

but what should i do if i want to update mu current timestamps?
-1

MySQL:

create table users(id int(10) unsigned auto_increment not null,name varchar(255) not null,email varchar(255) unique,password varchar(255) not null,remember_token varchar(100),created_at timestamp,updated_at  timestamp,  primary key (id))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.