Home > other >  Laravel 5.4 - MSSQL Error Invalid column name in Controller
Laravel 5.4 - MSSQL Error Invalid column name in Controller

Time:02-11

I'm trying to add a column to a controller in Laravel 5.4 but when I do I get this error:

SQLSTATE[42S22]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid column name 'Contract_SO_PO'.

Note: This is a new column in the database I recently created

Here is the code - I added 'contract.Contract_SO_PO' at the end of my select statement and in the groupBy:

public function index()
    {$records = DB::table('Contract')
            ->leftJoin('Contract_Line', 'Contract.Contract_ID','=','Contract_Line.Contract_ID')
            ->leftJoin('Contract_Product_Support_Bridge', 'Contract_Product_Support_Bridge.Contract_Line_ID','=','Contract_Line.Contract_Line_ID')
            ->leftJoin('Customer', 'Contract.Customer_ID','=','Customer.Customer_ID')
            ->select('contract.Contract_ID','customer.Customer_Name','contract.Contract_Contract_Number','contract.Contract_Quote_Number', 'contract.Contract_SO_PO', DB::raw('COUNT(*) AS Count_Records'))
            ->groupBy('contract.Contract_ID','customer.Customer_Name','contract.Contract_Contract_Number','contract.Contract_Quote_Number', 'contract.Contract_SO_PO')
            ->orderBy('Contract.Contract_ID','desc')
            ->get();


        return view('multi_records.index')->with('records',$records);
}

I tested the code with a column I know previously exists in the database and the code ran just fine.

Any suggestions? I'm wondering if this is an issue of Laravel not connecting to the database properly and therefore not reflecting new changes.

CodePudding user response:

I figured out the problem. I misconfigured my .env file to point to a different database than the one I was using. That was why database changes were not reflected.

  • Related