簡體   English   中英

在laravel 5中將數據插入mysql數據庫時出錯

[英]getting error while inserting data to mysql database in laravel 5

我的laravel應用程序正常運行我的數據庫但是當我試圖將數據插入我的數據庫時,我遇到了一個錯誤:

SQLSTATE [42S22]:未找到列:1054'字段列表'中的未知列'updated_at'(SQL:插入articlesarticle_headarticle_bodyupdated_atcreated_at )值(,2016-04-27 18:40:58, 2016-04-27 18:40:58))

我的視圖文件

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

我的控制器代碼

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

遷移文件

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

您的查詢嘗試更新時間戳。

你需要使用$table->timestamps(); 在遷移中,如果您不想使用它們,請將其添加到模型中:

public $timestamps = false;

有關時間戳的更多信息,請點擊此處

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM