erhsaikhasif's avatar

Base table or view not found: 1146 Table : getting error when inserting

I am trying to insert a record in table "mydb.events_timing" but it shows me error "Whoops, looks like something went wrong. 2/2 QueryException in Connection.php line 769: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydb.events__timings' doesn't exist (SQL: insert into events__timings (event_id, day, start_time, end_time) values (20, 22, 12345, 23456)) " I have table "'mydb.events_timing" with single underscore(_) and without character 's' at the end , but still it shows me 'mydb.events__timings' with in error message. Why double underscore sign(__) and character 's' is applied..? Also i created model file 'Events_Timing' with same class name.but not getting the issue.

0 likes
2 replies
nicolasboisvert's avatar
Level 2

Eloquent is really awesome, and it follows PSR-4. Your model should have been named EventTiming, singular, and only studly cased, eloquent will pair with a table event_timings, if it doesn't match your, you can override the property $table in your model to match the correct table. You said your table was events_timing, then in you model add this :

protected $table = 'events_timing';

Eloquent automatically get the table by (following convetions) snake-casing your model name and pluralizing:

Class User; users
Class UserProfile; users_profiles (or user_profiles, i'm not 100% sure);
Class Event_Timing; events__timings
etc...

I would first remove the _ in the model, for convention purposes, if it still don't match, override the property $table

If it doesn't help, please provide your migration and model class so you we can take a look with you

1 like
erhsaikhasif's avatar

Thank you So very much for the reply. The code is working for me. It was a very insane error that i stuck in that. I used "protected $table = 'events_timing';" in my model and it works. Thanks Again bro.

Please or to participate in this conversation.