title: Laravel 5.8 / Mysql: Cannot delete or update a parent row a foreign key constraint fails
body: <p>I am trying to setup my tables in my MySQL database and and I am currently creating migration files using Laravel 5.8. When I run a fresh migration with</p>
  
  <blockquote>
    <p>php artisan migrate</p>
  </blockquote>
  
  <p>all the migrations run smoothly and my foreign key is correctly added to my table</p>
  
  <p><a href="https://i.stack.imgur.com/jmfxK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jmfxK.png" alt="https://i.imgur.com/HIlR4i9.png"></a></p>
  
  <p>However when I want to update my database with</p>
  
  <blockquote>
    <p>php artisan migrate:refresh</p>
  </blockquote>
  
  <p>I run into this error</p>
  
  <blockquote>
    <p>Illuminate\Database\QueryException  : <strong>SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (SQL: drop table if exists <code>services</code>)</strong></p>
  </blockquote>
  
  <p>What I've tried so far:</p>
  
  <p>Splitting my foreign keys in different migration files so that they come after my tables that doesn't have foreign keys in them</p>
  
  <p>File architecture in visual studio code</p>
  
  <p><a href="https://i.stack.imgur.com/FLhFE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FLhFE.png" alt="File Architecture"></a></p>
  
  <p>adding <strong>->onDelete('cascade')</strong> on each foreign key in my up() functions (code below)</p>
  
  <p>My <strong>Services</strong> migration file</p>
  
  <pre><code>class CreateServicesTable extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up()
      {
          Schema::create('services', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;string('name');
              $table-&gt;text('description');
              $table-&gt;integer('price');
              $table-&gt;boolean('multiple_times');
              $table-&gt;boolean('location');
              $table-&gt;integer('animal_type_id')-&gt;unsigned();
              $table-&gt;timestamps();
          });
      }
  
      /**
       * Reverse the migrations.
       *
       * @return void
       */
      public function down()
      {
          Schema::dropIfExists('services');
      }
  }
  </code></pre>
  
  <p>My <strong>AnimalType</strong> foreign key</p>
  
  <pre><code>class ForeignKeyAnimalTypeServices extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up()
      {
          Schema::table('services', function($table){
              $table-&gt;foreign('animal_type_id')-&gt;references('id')-&gt;on('animal_types')-&gt;onDelete('cascade');
          });
      }
  
      /**
       * Reverse the migrations.
       *
       * @return void
       */
      public function down()
      {
          Schema::dropIfExists('services', function(Blueprint $table){
              $table-&gt;dropForeign(['animal_type_id']);
          });
      }
  }
  </code></pre>
  
  <p>My <strong>Service</strong> model</p>
  
  <pre><code>class Service extends Model
  {
      protected $table = 'services';
      protected $fillable = [
          'name', 'description', 'price', 'multiple_times', 'location'
      ];
  
      public function animalType()
      {
          return $this-&gt;belongsTo('App\AnimalType');
      }
  }
  </code></pre>
  
  <p>Although my migrations are created, I can't refresh my migrations if I need to (or seed my table). I want to be able to refresh my files without getting this error.
  I am still pretty new to programming, my apologies if there is missing information.</p>