Support the ongoing development of Laravel.io →
Database Packages Installation

i got some error like this :

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

the query search 'id' column when my column name is not 'id' but 'id_user',
i want ask how to edit the code from

select * from `tbl_user` where `tbl_user`.`id` = 1 limit 1

on laravel to :

select * from `tbl_user` where `tbl_user`.`id_user` = 1 limit 1

this is my migration..

public function up()
    {
        Schema::create('tbl_user', function (Blueprint $table) {
            $table->increments('id_user');
            $table->string('nama_user', 50);
			$table->string('level_akses', 30);
			$table->string('status', 7)->default('offline');
			$table->string('contact', 14);
			$table->string('eMail', 70);
			$table->string('password', 30);
			$table->timestamps();
        });
    }
Last updated 2 years ago.
0

Specify the primary key in your model:

protected $primaryKey = 'id_user';

https://laravel.com/docs/5.3/eloquent

0

Sign in to participate in this thread!

Eventy

Your banner here too?

DCHN04 dchn04 Joined 4 Oct 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.