Adhe Widianjaya
Adhe Widianjaya

Reputation: 85

Laravel Eloquent returns QueryException, Base table or view not found

I implemented laravel eloquent to retrieve data from database (I use mysql). I had performed migration to create table 'r_prereportagen' with migration file '2015_09_04_200539_create_pre_reportagens_table.php'. A file named pre_reportagen.php was appeared in /app directory, I used the class pre_reportagen defined in pre_reportagen.php and my application ends up with error: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'appumrohsurabaya.pre_reportagens' doesn't exist (SQL: select * from pre_reportagens). I've examined my database, and I was sure that my table 'r_prereportagen' was there. Is anyone find the mistakes?

Upvotes: 0

Views: 1042

Answers (2)

abhishek.agarwal
abhishek.agarwal

Reputation: 36

you are sure that r_prereportagen exists in your database, but eloqunt looking 'pre_reportagens' table. still if you want your table name as r_prereportagen just overwrite the table name on your pre_reportagen.php files, just before fillables property

protected $table = 'r_prereportagen';

Upvotes: 2

Douwe de Haan
Douwe de Haan

Reputation: 6646

Eloquent expects a table that is the plural of the model name. In your error it already states that it is looking for a table named appumrohsurabaya.pre_reportagens while you created the singular version (appumrohsurabaya.pre_reportagen, without the s).

So in your model, set the following code:

protected $table = "r_prereportagen"

Upvotes: 0

Related Questions