I know this has been asked many times before but I have already been searching for an answer for the last 3 hours on stackoverflow with no success, none of the solutions work in my case. My model relationships are working fine on localhost but as soon as push my changes to production server (with the same config), relationships between models stop working.
Here is my File.php model relationship with Language.php model
public function language()
{
return $this->belongsTo('App\Language', 'language_id', 'id');
}
I have even specified the keys by which to link them.
Here's where the problem occurs. On my local machine, everything works great with this code
$files = File::orderBy('updated_at', 'DESC')->get();
return $files[0]->language;
Now when I do the same on production server, I get empty result.
You might say that the problem is with records on database, well it's not.
Here's a proof:
File record from production database
And here's the languages table
Data types of foreign key column (language_id and id column in languages table data types are both unsigned bigIntegers with length of 20).
It's not just a problem with languages model, I have some other models linked with the same logic and none of them work in production, despite them working on local host.
By the way, in phpmyadmin on localhost I can select values based on foreign key connection, however on server I cannot do that:
Server:
Any help would be much appreciated
EDIT: I have found that there was an issue with table engine, had to be set as innoDB (check the answers), so that fixes the database issue. However, I still have problems with Laravel recognizing these relationships.