title: Laravel Foreign Key Integrity constraint violation
body: <p>I have one foreign key in my database named images.</p>
  
  <p>This is its Migration:</p>
  
  <pre><code>class CreateImagesTable extends Migration
  {
  
      public function up()
      {
          Schema::create('images', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;integer('product_id')-&gt;unsigned();
              $table-&gt;integer('product_r_id')-&gt;unsigned();
              $table-&gt;string('name', 50);
              $table-&gt;text('images', 50);
              $table-&gt;foreign('product_id')-&gt;references('id')-&gt;on('products')-&gt;onDelete('cascade')-&gt;onUpdate('cascade');
              $table-&gt;timestamps();
          });
  
          Schema::table('images', function (Blueprint $table) {
              $table-&gt;foreign('product_r_id')-&gt;references('id')-&gt;on('products_r')-&gt;onDelete('cascade')-&gt;onUpdate('cascade');
          });
      }
  
      public function down()
      {
          Schema::drop('images');
      }
  
  }
  </code></pre>
  
  <p>Its Model looks like this:</p>
  
  <pre><code>class Images extends Model
  {
      protected $table = 'images';
  
      protected $fillable = ['product_id', 'product_r_id', 'name', 'images'];
  
      public function product()
      {
          return $this-&gt;belongsTo('App\Product', 'product_id');
      }
  
      public function productR()
      {
          return $this-&gt;belongsTo('App\ProductR', 'product_r_id');
      }
  
  }
  </code></pre>
  
  <p>ProductR Model looks like this:</p>
  
  <p>
  
  <pre><code>class ProductR extends Model
  {
      protected $table = 'products_r';
  
      protected $fillable = ['email', 'title', 'filename', 'inputMpg', 'number_of_chapters'];
  
      public function images()
      {
          return $this-&gt;hasMany('App\Images');
      }
  
  }
  </code></pre>
  
  <p>And Product Model like this:</p>
  
  <pre><code>class Product extends Model
  {
      protected $table = 'products';
  
      protected $fillable = ['email', 'title', 'filename', 'inputMpg', 'number_of_chapters'];
  
      public function scenesImages()
      {
          return $this-&gt;hasMany('App\Images');
      }
  }
  </code></pre>
  
  <p>So I basicaly try to save in two different forms different products with their image into the same table in my database (images).</p>
  
  <p>Running my Program returns me this error:</p>
  
  <blockquote>
    <p>QueryException in Connection.php line 655: SQLSTATE[23000]: Integrity
    constraint violation: 1452 Cannot add or update a child row: a foreign
    key constraint fails (<code>mydb</code>.<code>images</code>, CONSTRAINT
    <code>images_product_id_foreign</code> FOREIGN KEY (<code>product_id</code>) REFERENCES
    <code>products</code> (<code>id</code>) ON DELETE CASCADE ON UPDATE CASCADE) (SQL: insert
    into <code>images</code> (<code>name</code>, <code>images</code>, <code>product_r_id</code>, <code>updated_at</code>,
    <code>created_at</code>) values (ki, 0Chrysanthemum.jpg, 10, 2016-05-20 10:50:51,
    2016-05-20 10:50:51))</p>
  </blockquote>