laraveleloquent

SQLSTATE[HY000]: General error: 1 no such table - laravel 11


I'm kind of new to laravel, and get this error while I was trying store some data:

SQLSTATE[HY000]: General error: 1 no such table: main.user

my code is this:

$club = new Club();
$club->name = $request->name;
$club->user_id = $request->id;
$club->status = true;
$club->save();
$success = 'activated successfully';

return view('admin.clubs.new_club', compact('success'));

my table clubs with these columns id,name,user_id,status. the column user_id is a foregin id for users table.

it point to save() as the cause of the error but I don't know why. I have the same form but for user and it works


Solution

  • Thank you for your help, I figure it out, I was using this code in the migration of club table:

    $table->foreignId('user_id')->constrained('user');
    

    The mistake I have done is I wrote user instead of users