PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, March 11, 2022

[FIXED] Laravel 5.4 - MSSQL Error Invalid column name in Controller

 March 11, 2022     laravel-5, php, sql-server     No comments   

Issue

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.


Solution

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.



Answered By - Avery Lytle
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing