vendredi 6 janvier 2017

Laravel 5 schema for many to many issue

I've got a many to many pivot table created with properties that are giving SQL an issue.

Schema:

class CreateLinkUserTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('link_user', function(Blueprint $table)
        {
            $table->increments('id');
            $table->integer('link_id')->unsigned()->index();
            $table->foreign('link_id')->references('id')->on('links');
            $table->integer('user_id')->unsigned()->index();
            $table->foreign('user_id')->references('id')->on('users');
            $table->timestamps();
        });
    }


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

}

I'm getting errors from SQL as follows:

[Illuminate\Database\QueryException] SQLSTATE[HY000]: General error: 1005 Can't create table laralara.#sql-1d64_37 (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table link_user add constraint link_user_link_id_foreign foreign key (link_id) references links (id))

It actually does create the pivot table, yet i'm trying to avoid any future issues that should arise, when deploying, etc. Please let me know if this needs fixing and if so, how.

Pleasantries & Salutations,

Clusterbuddy



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2jm4dA9
via IFTTT

Aucun commentaire:

Enregistrer un commentaire