title: LARAVEL:MYSQL : Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
body: <p>I am trying to apply a foreign Key to column user_id, related with ID of table <strong>users</strong></p>
  
  <p>I have tried doing it by migrations and in workbench and this error keeps coming:</p>
  
  <blockquote>
    <p>Integrity constraint violation: 1452 Cannot add or update      a child
    row: a foreign key constraint fails</p>
  </blockquote>
  
  <p>this is the mysql:</p>
  
  <pre><code>ALTER TABLE `dh_booky`.`books` 
  
  ADD CONSTRAINT `books_user_id_foreign`
  
    FOREIGN KEY (`user_id`)
  
    REFERENCES `dh_booky`.`users` (`id`)
  
    ON DELETE NO ACTION
  
    ON UPDATE NO ACTION;
  </code></pre>
  
  <p>1st migration books:</p>
  
  <pre><code> public function up()
      {
          Schema::create('books', function (Blueprint $table) {
              $table-&gt;bigIncrements('id');
              $table-&gt;bigInteger('title_id')-&gt;unsigned();
              $table-&gt;foreign('title_id')-&gt;references('id')-&gt;on('titles');
              $table-&gt;bigInteger('author_id')-&gt;unsigned();
              $table-&gt;foreign('author_id')-&gt;references('id')-&gt;on('authors');
              $table-&gt;string('image')-&gt;nullable();
  
          });
      }
  </code></pre>
  
  <p>Update migration books: </p>
  
  <pre><code>class UpdateBooksTable extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up()
      {
          Schema::table('users', function (Blueprint $table) {
          $table-&gt;bigInteger('user_id')-&gt;unsigned();
          $table-&gt;foreign('user_id')-&gt;references('id')-&gt;on('users');
          //php artisan make:migration update_votes_table
  
  
  
  });
  </code></pre>
  
  <p>User migration:</p>
  
  <pre><code>public function up()
      {
          Schema::create('users', function (Blueprint $table) {
              $table-&gt;bigIncrements('id');
              $table-&gt;timestamps();
              $table-&gt;string('name');
              $table-&gt;string('email')-&gt;unique();
              $table-&gt;string('password');
              $table-&gt;rememberToken();
          });
      }
  </code></pre>