A
A
Analka2019-09-12 17:09:01
Database migration
Analka, 2019-09-12 17:09:01

Laravel 6 migration failing?

Why does the migration fail?

public function up()
    {
        Schema::create('article_galleries', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('article_id')->index();
            $table->foreign('article_id')
                ->references('id')->on('articles')
                ->onDelete('cascade');
            $table->string('title')->nullable();
            $table->mediumText('description')->nullable();
            $table->string('image')->nullable();
            $table->timestamps();
        });
    }

gives an error message
Migrating: 2019_08_06_195958_create_article_galleries_table

Illuminate\Database\QueryException  : SQLSTATE[HY000]: General error: 3780 Referencing column 'articles_id' and referenced column 'id' in foreign key constraint 'article_galleries_articles_id_foreign' are incompatible. (SQL: alter table `article_galleries` add constraint `article_galleries_articles_id_foreign` foreign key (`articles_id`) references `articles` (`id`) on delete cascade)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question