O erro exato que estou recebendo é:
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table
course_user
add constraintcourse_user_course_code_foreign
foreign key (course_code
) referencescourses
(code
))
Li muitas soluções, mas nenhuma parece corrigir meu problema. Eu tentei;
Aqui está minha course_user
migration
public function up()
{
Schema::create('course_user', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->integer('user_id')->unsigned();
$table->string('course_code');
});
Schema::table('course_user', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->foreign('user_id')->references('id')->on('users');
$table->foreign('course_code')->references('code')->on('courses');
$table->timestamps();
//$table->primary(['user_id', 'course_code']);
});
}
Aqui está minha course
migration
public function up()
{
Schema::create('courses', function (Blueprint $table) {
//$table->increments('id');
$table->increments('id');
$table->string('code');
$table->string('name');
$table->timestamps();
});
}
Tags mysql