I'm having trouble with this error because I have already followed the other solution but it's still showing to me. Even tho on other migration seems working on. Here's my code
Schema::create('student', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users');
$table->string('first_name');
$table->string('middle_name')->nullable();
$table->string('last_name');
$table->unsignedBigInteger('course_id');
$table->foreign('course_id')->references('id')->on('courses');
$table->timestamps();
});
This migration file is last and my IDs on courses and users are $table->id()
by default and like I said this code is working on my other migration files.
CodePudding user response:
I don't know if it makes sense. But it all works out when I change the table name of the student into students. This is so weird on my side because that is not showing on the error. Anyway, If someone came up with the same problem as I just try changing the table name.
CodePudding user response:
Laravel's convention is plural table names by default. It makes sense because you are probably storing multiple data's in the table.
You can add this in your model and get away with your issue.
protected $table = 'singular';
Here's a good discussion about your problem.
https://laracasts.com/discuss/channels/eloquent/laravel-table-names-are-plural-by-default?page=1