php - 在 laravel 5 中向 mysql 数据库插入数据时出错

标签 php mysql laravel laravel-5

我的数据库在我的 laravel 应用程序中运行良好,但是当我尝试将数据插入我的数据库时,我遇到了一个错误:

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

我的查看文件

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

我的 Controller 代码

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;

有关时间戳的更多信息是 here .

关于php - 在 laravel 5 中向 mysql 数据库插入数据时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36898486/

相关文章:

php - 0 字段是必需的。 Laravel 5.5 验证错误

Laravel 4 的 nginx 配置

php - 使用 Laravel Doctrine 的 InvalidFieldNameException

php mysqli/multi_query 不能进行多次

php - Innodb引擎不支持全文索引,如何进行文本搜索?

MySQL 存储过程 - 计算不同工资率的工资

mysql - 如何在 Eloquent 中查询 JSON 列中的数组

php - 无法从表中检索数据?

php - 使用 SimpleXML 读取参数名称

javascript - POST Jquery AJAX 错误 500