I'm using Laravel 5.4 and I have added this Migration:
public function up()
{
Schema::create('episodes', function (Blueprint $table) {
$table->increments('id');
$table->integer('course_id')->unsigned();
$table->foreign('course_id')->references('id')->on('courses')->onDelete('cascade');
$table->string('type', 10);
$table->string('title');
$table->string('slug');
$table->text('description');
$table->text('body');
$table->string('videoUrl');
$table->string('tags');
$table->string('time', 15)->default('00:00:00');
$table->integer('number');
$table->integer('viewCount')->default(0);
$table->integer('commentCount')->default(0);
$table->integer('downloadCount')->default(0);
$table->timestamps();
});
}
Now when I run php artisan migrate
, I get this error:
SQLSTATE[HY000]: General error: 1005 Can't create table elearning
.episodes
(errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table episodes
add constraint episodes_course_id_foreign
foreign key (course_id
) references courses
(id
) on delete cascade)
I also tried this but still gets the same error:
$table->unsignedBigInteger('course_id');
So how can I properly run this Migration? I'm really stuck with this, please help me out...
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3EC7ctm
via IFTTT
Aucun commentaire:
Enregistrer un commentaire