Error on migration

Posted 6 days ago by tastemedia

Hi there, i´m getting an error when i want to do migration.

Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table tag_videofile add constraint tag_videofile_tag_id_foreign foreign key (tag_id) references tags (id))

here´s my migration file:


class CreateTagVideofileTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('tag_videofile', function (Blueprint $table) {
            $table->unsignedBigInteger('videofile_id');
            $table->foreign('videofile_id')->references('id')->on('videofiles');
            $table->unsignedBigInteger('tag_id');
            $table->foreign('tag_id')->references('id')->on('tags');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('tag_videofile');
    }


what i´m doing wrong here? Ccan someone help me out? thx in advance.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.