简体   繁体   中英

getting error while inserting data to mysql database in laravel 5

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');
        });
    }

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM