I am working on a new laravel 5.5 site and am getting an exception I don't understand when the application tries to connect to a Postgresql database.
All settings in my env file are correct for the database connection
I am creating the table with a migration and when I run php artisan migrate the table gets created.
Under /app I have a file NbnCo.php that contains
class NbnCo extends Model
{
protected $fillable=[
// All the db table fields are here
];
}
Under /app/Http/Controllers I have NbnCoController.php
It contains
namespace App\Http\Controllers;
use App\NbnCo;
use Illuminate\Http\Request;
use App\Http\Requests;
class NbnCoController extends Controller
{
public function showForm()
{
return view('upload');
}
public function store(Request $request)
{
//get file
$upload=$request->file('upload-file');
$filePath=$upload->getRealPath();
//open and read
$file=fopen($filePath, 'r');
$header= fgetcsv($file);
$processedHeader=[];
//validate
foreach ($header as $key => $value) {
$lheader=strtolower($value);
array_push($processedHeader, $lheader);
}
while($columns=fgetcsv($file))
{
if($columns[0]=="")
{
continue;
}
$data=array_combine($processedHeader, $columns);
// Table update
$nbn_location_identifier=$data['nbn_location_identifier'];
// the rest of the folumns follow the same style
$nbn = NbnCo::firstOrNew(['nbn_location_identifier'=>$nbn_location_identifier]);
// the rest are added in the same way
$nbn->save();
}
}
}
The idea is that a simple form is displayed and a CSV file is selected to be uploaded into the nbnco table in the nbn database.
I am getting 2 PDO errors
PDOException in Connection.php line 337:
SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "nbn_cos" does not
exist
LINE 1: select * from "nbn_cos" where ("nbn_location_identifier" = $...
^
and
QueryException in Connection.php line 770:
SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "nbn_cos" does not
exist
LINE 1: select * from "nbn_cos" where ("nbn_location_identifier" = $...
^ (SQL: select * from "nbn_cos" where ("nbn_location_identifier" =
LOC000012257222) limit 1)
I do not understand where the nbn_cos table that laravel is trying to connect to is coming from. I also don't understand where the nbn_cos relation is coming from.
The best I can find is that I am doing something wrong with the naming of my classes and the name of the database table. I can't work out, even with a lot of Google searching, where the database table name is actually passed to the connection and SQL statements.