【问题标题】:Laravel - SQLSTATE[42S22]: Column not found: 1054 Unknown column in field listLaravel - SQLSTATE [42S22]:找不到列:1054 字段列表中的未知列
【发布时间】:2015-01-19 19:45:29
【问题描述】:

我需要使用 laravel 将一个简单的表单数据添加到数据库中
每次表单发布时,数据都会进入数据库,但我收到此错误

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'tf.FirstName' in 'field list' (SQL: insert into `tbl_fundraising_pages` (`Permalink`, `Name`, `Summary`, `Story`, `Goal_Amount`, `End_Date`, `Designation`, `WebAddress`, `Block_SearchEngine`, `CharityID`, `updated_at`, `created_at`) values (Something-Like-That, Something Like That, Something Like That, <p>Something Like That</p> , 500, 11/04/2014, General Fund, Something-Like-That, NewDesig, 1387, 2014-11-21 15:14:19, 2014-11-21 15:14:19)

数据库中没有 tf.FirstName 字段,查询也没有 模态

<?php
class Fundraising extends Eloquent{
    protected $table = 'tbl_fundraising_pages';
    protected $fillable = [
        'fundraiser_id',
        'Permalink',
        'Name',
        'Summary',
        'Story',
        'Goal_Amount',
        'End_Date',
        'Designation',
        'WebAddress',
        'Block_SearchEngine',
        'CharityID'
        ];
}

控制器功能

public function postCreatePage(){
        $charities = Charities::where('Charity_Name','=',''.Input::get('NonprofitName').'')->first();
        $data = array(
          'Permalink' => str_replace(' ', '-', Input::get('FundraiserName')),
          'Name' => Input::get('FundraiserName'),  
          'Summary' => Input::get('Summary'),  
          'Story' => Input::get('YourPassion'), 
          'Goal_Amount' => Input::get('GoalAmount'),
          'Designation' => Input::get('Designation'),
          'WebAddress' => str_replace(' ', '-', Input::get('FundraiserName')),
          'Block_SearchEngine' => Input::get('NewDesig')
        );
        if(Input::get('NonprofitName')){
            $data['CharityID'] = $charities->ID;
        }
        $page = new Fundraising();
        foreach ($data as $key => $insert){
            $page->$key = $insert;
        }
        if($page->save()){
            return Response::json(array('message' => 'Done'));
        }


    }

我不知道这个文件是从哪里来的?
HTML 表单中没有任何内容 在 Ajax 调用中没有任何内容

【问题讨论】:

  • 有没有可能是某种 SQL 触发器导致了这种情况?
  • 我没有使用任何 SQL 触发器
  • 你的迁移是什么?

标签: php laravel laravel-4


【解决方案1】:

可能在您迁移的某个地方,定义了FirstName 列,因为错误告诉我们有关Unknown column 'tf.FirstName' 的信息。由于您的控制器没有对这个专栏做任何事情,我建议找到它并删除它。

【讨论】:

    【解决方案2】:

    表中不存在FirstName 列,但我可以看到您有一个列Name 可能就是这个列。

    【讨论】:

      猜你喜欢
      • 2018-02-21
      • 2015-12-08
      • 2018-11-02
      • 2019-10-02
      • 2019-05-28
      • 2015-04-20
      • 1970-01-01
      • 2017-04-03
      相关资源
      最近更新 更多