title: Many to Many on Laravel migration
body: <p>I have 3 tables to connect each other. Tables name's roles, role_user, and users. I want to make migration on laravel and adding some constraint. and here's what in my role tables migration:</p>
  
  <pre><code>    Schema::create('roles', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;string('name');
          $table-&gt;string('description');
          $table-&gt;timestamps();
      });
  </code></pre>
  
  <p>and here's my Users table migration:</p>
  
  <pre><code>Schema::create('users', function (Blueprint $table) {
      $table-&gt;increments('id');
      $table-&gt;string('username')-&gt;unique();
      $table-&gt;string('name');
      $table-&gt;string('email')-&gt;unique();
      $table-&gt;string('password');
      $table-&gt;boolean('active')-&gt;default(0);
      $table-&gt;softDeletes();
      $table-&gt;rememberToken();
      $table-&gt;timestamps();
  });
  </code></pre>
  
  <p>and here's my role_user table migration:</p>
  
  <pre><code>    Schema::create('role_user', function (Blueprint $table) {
          $table-&gt;integer('role_id')-&gt;unsigned();
          $table-&gt;integer('user_id')-&gt;unsigned();
  
          $table-&gt;unique(['role_id', 'user_id']);
          $table-&gt;foreign('role_id')-&gt;references('id')-&gt;on('roles')
              -&gt;onDelete('cascade')-&gt;onUpdate('cascade');
          $table-&gt;foreign('user_id')-&gt;references('id')-&gt;on('users')
              -&gt;onDelete('cascade')-&gt;onUpdate('cascade');
      });
  </code></pre>
  
  <p>in my Migration order i put roles table on top of users already but i got this kind of errors:</p>
  
  <pre><code>  [Illuminate\Database\QueryException]
    SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `role_user` add constraint `role_user_role_id_foreign` foreign key (`role_id
    `) references `roles` (`id`) on delete cascade on update cascade)
  
  
  
    [PDOException]
    SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
  </code></pre>