vendredi 25 octobre 2019

Can not update child row laravel

I'm trying to insert product_id and user_id into the database but I'm getting an error:

Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails

How can I solve this?

Blade File:

<form action="" id="contact_form" method="post">
 
  <input name="user_id" type="text" value="" />
    <input name="product_id" type="text" value="" />
      <button type="submit" >
     
  </button>
</form>

Migrations:

  public function up()
{
    Schema::create('wishlist', function (Blueprint $table) {
        $table->bigIncrements('id');

        $table->bigInteger('user_id')->nullable()->unsigned();
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');

        $table->bigInteger('product_id')->nullable()->unsigned();
        $table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');

        $table->timestamps();
    });
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire