0
votes

Table Schema

Create Table User
(
    UserID int,
    FirstName varchar(50)
)

User Model

class User_Model extends Model
{
    protected $table = "user";
}

Below is my code in Laravel 5

$users = \App\Models\User_Model::find(1);

Error Message

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user.id' in 'where clause' (SQL: select * from user where user.id = 1 limit 1)

1
Can you please paste the output of "SHOW CREATE TABLE user" from the database?Bryan
Do you want to check the Table Schema ?Pankaj
I'm curious to know if the column truly exists, or perhaps your table's name is actually "users" instead of "user"Bryan
Laravel is saying : user.id and My primary key is UserID.Pankaj

1 Answers

2
votes

You've updated your table name, you also need to set the primary key you're using as it's not the assumed id field

class User_Model extends Model
{ 
    protected $table = "user";
    protected $primaryKey = "UserID";
}