title: Laravel seeder integrity constraint violation 1452
body: <p>I created table Users, Products, Oders, Oder_Items. 
  this is for a ecommerce, i want that each product have a author (user).
  Artisan give a error :</p>
  
  <blockquote>
    <p>integrity constraint violation 1452 Cannot add or update a child row:
    a foreign key constraint fails ('2016', 'products', CONSTRAINT
    'products_user_id_foreign' FOREIGN KEY ('user_id') REFERENCES 'users'
    ('id') ON DELETE CASCADE).</p>
  </blockquote>
  
  <p>Migration work good. Seeder information no.</p>
  
  <p>MIGRATION ORDERS_ITEMS:</p>
  
  <pre><code>&lt;?php
  
  use Illuminate\Database\Schema\Blueprint;
  use Illuminate\Database\Migrations\Migration;
  
  class CreateOrderItemsTable extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up()
      {
          Schema::create('order_items', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;decimal('price', 5, 2);
              $table-&gt;integer('quantity')-&gt;unsigned();
  
  
  
  
  
  
              //--------// ogni item ha un prodotto ID
              $table-&gt;integer('product_id')-&gt;unsigned();
              $table-&gt;foreign('product_id')
                    -&gt;references('id')
                    -&gt;on('products')
                    -&gt;onDelete('cascade');
  
              // Ogni item ha un ORDER ID, cosi possiamo filtrare tutti gli item degli ordini   
              $table-&gt;integer('order_id')-&gt;unsigned();
              $table-&gt;foreign('order_id')
                    -&gt;references('id')
                    -&gt;on('orders')
                    -&gt;onDelete('cascade');;
           });
  
  
  
  
  
      }
  
      /**
       * Reverse the migrations.
       *
       * @return void
       */
      public function down()
      {
          Schema::drop('order_items');
      }
  }
  </code></pre>
  
  <p>MIGRATION ORDERS</p>
  
  <pre><code>&lt;?php
  
  use Illuminate\Database\Schema\Blueprint;
  use Illuminate\Database\Migrations\Migration;
  
  class CreateOrdersTable extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up()
      {
          Schema::create('orders', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;decimal('subtotal', 5, 2);
              $table-&gt;decimal('shipping', 5,2);
  
  
  
              $table-&gt;timestamps();  
  
  
  
  
  
           });
      }
  
      /**
       * Reverse the migrations.
       *
       * @return void
       */
      public function down()
      {
          Schema::drop('orders');
      }
  }
  </code></pre>
  
  <p>MIGRATION PRODUCTS</p>
  
  <pre><code>&lt;?php
  
  use Illuminate\Database\Schema\Blueprint;
  use Illuminate\Database\Migrations\Migration;
  
  class CreateProductsTable extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
  
      //Up creare table
      public function up()
      {
          Schema::create('products', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;string('name', 255);
              $table-&gt;string('slug'); 
              $table-&gt;text('description');
              //mostrare una piccola descrizione del prodotto
              $table-&gt;string('extract', 300);
              $table-&gt;decimal('price', 5, 2);
              $table-&gt;string('image', 300);
              //vedere se pubblico o no
              $table-&gt;boolean('visible');
              // unsigned solo valori positivi
              //e fa riferimento al id category, 
              //Se si cancella, cancellerà tutti i prodotti con quella categoria
              //Ogni prodotto ha una categoria
  
              $table-&gt;integer('user_id')-&gt;unsigned();
  
              $table-&gt;foreign('user_id')
                    -&gt;references('id')-&gt;on('users')
                    -&gt;onDelete('cascade');
  
  
  
  
  
  
  
              $table-&gt;integer('category_id')-&gt;unsigned();
  
              // relazioni  
              $table-&gt;foreign('category_id')
                    -&gt;references('id')
                    -&gt;on('categories')
                    -&gt;onDelete('cascade');
              //crea // Ogni prodotto ha un autore( artista)
  
  
  
  
              // ----// 
              $table-&gt;timestamps();
          });
      }
  
      /**
       * Reverse the migrations.
       *
       * @return void
       */
      //eliminare table
      public function down()
      {
          Schema::drop('products');
      }
  }
  </code></pre>
  
  <p>MIGRATION USERS</p>
  
  <pre><code>&lt;?php
  
  use Illuminate\Database\Schema\Blueprint;
  use Illuminate\Database\Migrations\Migration;
  
  class CreateUsersTable extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
     public function up()
  
  {
  
      Schema::create('users', function (Blueprint $table) {
  
          $table-&gt;increments('id');
  
          $table-&gt;string('name');
  
          $table-&gt;string('lastname');
  
          $table-&gt;string('username');
  
          $table-&gt;string('birth');
  
          $table-&gt;string('profile');
  
          $table-&gt;string('country');
  
          $table-&gt;string('province');
  
          $table-&gt;string('address');
  
          $table-&gt;string('address2');
  
          $table-&gt;string('phone');
  
          $table-&gt;string('usertype');
  
          $table-&gt;string('email')-&gt;unique();
  
          $table-&gt;string('password', 60);
  
          $table-&gt;boolean('social');
  
          $table-&gt;boolean('active')-&gt;default(0);
  
          $table-&gt;string('confirm_token', 100);
  
          $table-&gt;rememberToken();
  
          $table-&gt;timestamps();
  
      });
  
  }
  
  
  
  
  
  
      /**
       * Reverse the migrations.
       *
       * @return void
       */
      public function down()
      {
          Schema::drop('users');
      }
  }
  </code></pre>
  
  <p>PRODUCTS SEEDER</p>
  
  <pre><code>&lt;?php
  
  use Illuminate\Database\Seeder;
  use Illuminate\Database\Eloquent\Model;
  
  //Con questo gli dico di usare il mio modello per questo SEEDER
  use dixard\Product;
  
  class ProductTableSeeder extends Seeder
  {
      /**
       * Run the database seeds.
       *
       * @return void
       */
      public function run()
      {
  
  
  
              DB::table('products')-&gt;insert([
              'name'          =&gt; 'Playera 1',
                  'slug'          =&gt; 'playera-1',
                  'description'   =&gt; 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Delectus repellendus doloribus molestias odio nisi! Aspernatur eos saepe veniam quibusdam totam.',
                  'extract'       =&gt; 'Lorem ipsum dolor sit amet, consectetur adipisicing elit.',
                  'price'         =&gt; 275.00,
                  'image'         =&gt; 'http://www.truffleshuffle.co.uk/store/images_high_res/Mens_Red_Batman_Graffiti_Logo_T_Shirt_hi_res.jpg',
                  'visible'       =&gt; 1,
  
                  'created_at'    =&gt; new DateTime,
                  'updated_at'    =&gt; new DateTime,
                  'category_id'   =&gt; 1,
                  'user_id'   =&gt; 1,
          ]);
  
  
  
  
      }
  }
  </code></pre>
  
  <p>I CALLED SEEDER :</p>
  
  <pre><code>&lt;?php
  
  use Illuminate\Database\Seeder;
  use Illuminate\Database\Eloquent\Model;
  
  class DatabaseSeeder extends Seeder
  {
      /**
       * Run the database seeds.
       *
       * @return void
       */
      public function run()
      {
          Model::unguard();
  
          // $this-&gt;call(UserTableSeeder::class);
          $this-&gt;call(CategoryTableSeeder::class);
          $this-&gt;call(ProductTableSeeder::class);
  
  
          Model::reguard();
      }
  }
  </code></pre>