在laravel 5中将数据插入mysql数据库时出错

时间:2016-04-27 18:52:39

标签: php mysql laravel laravel-5

我的laravel应用程序正常运行我的数据库但是当我试图将数据插入我的数据库时,我遇到了错误:

  

SQLSTATE [42S22]:未找到列:1054未知列' updated_at'在   '字段列表' (SQL:插入articlesarticle_head,   article_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');
        });
    }

2 个答案:

答案 0 :(得分:5)

您的查询尝试更新时间戳。

您需要在迁移中使用$table->timestamps();,或者如果您不想使用它们,请将其添加到您的模型中:

public $timestamps = false;

有关时间戳的更多信息,请here

答案 1 :(得分:-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))