title: Adding Foreign Key using Phinx
body: <p>I know there has been a couple of posts similar to this one, but they are not giving me the answer I need. So, I'm using Phinx and I am trying to add a foreign key, but I get the following error:</p>
  
  <pre><code>General error: 1215 Cannot add foreign key constraint
  </code></pre>
  
  <p>Here is the php file with the foreign keys:</p>
  
  <pre><code>&lt;?php
  
  use Phinx\Migration\AbstractMigration;
  
  class CustomQuotes extends AbstractMigration
  {
      /**
       * Change Method.
       *
       * Write your reversible migrations using this method.
       *
       * More information on writing migrations is available here:
       * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
       *
       * The following commands can be used in this method and Phinx will
       * automatically reverse them when rolling back:
       *
       *    createTable
       *    renameTable
       *    addColumn
       *    renameColumn
       *    addIndex
       *    addForeignKey
       *
       * Remember to call "create()" or "update()" and NOT "save()" when working
       * with the Table class.
       */
      public function change()
      {
          $table = $this-&gt;table('custom_quotes', ['id' =&gt; false, 'primary_key' =&gt; ['custom_quote_id']]);
          $table-&gt;addColumn('custom_quote_id', 'biginteger', ['identity' =&gt;true, 'signed' =&gt; false])
          -&gt;addColumn('account_id', 'biginteger', ['limit' =&gt; 20, 'null' =&gt; true])
          -&gt;addColumn('quote_type_id', 'integer', ['limit' =&gt; 11, 'null' =&gt; true])
          -&gt;addColumn('quote', 'string', ['limit' =&gt; 500, 'null' =&gt; true])
          -&gt;addColumn('selected', 'integer', ['limit' =&gt; 4, 'null' =&gt; true, 'default' =&gt; 1])
          -&gt;addForeignKey('account_id', 'accounts', 'account_id', array('delete'=&gt; 'NO_ACTION', 'update'=&gt; 'NO_ACTION'))
          -&gt;addForeignKey('quote_type_id', 'quote_types', 'quote_type_id', array('delete'=&gt; 'NO_ACTION', 'update'=&gt; 'NO_ACTION'))
          -&gt;create();
      }
  }
  </code></pre>
  
  <p>The two tables I am trying to get the id from are created before the table above. Here are the other two tables:</p>
  
  <p>Quote types table
      
  
  <pre><code>use Phinx\Migration\AbstractMigration;
  
  class CustomQuotes extends AbstractMigration
  {
      /**
       * Change Method.
       *
       * Write your reversible migrations using this method.
       *
       * More information on writing migrations is available here:
       * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
       *
       * The following commands can be used in this method and Phinx will
       * automatically reverse them when rolling back:
       *
       *    createTable
       *    renameTable
       *    addColumn
       *    renameColumn
       *    addIndex
       *    addForeignKey
       *
       * Remember to call "create()" or "update()" and NOT "save()" when working
       * with the Table class.
       */
      public function change()
      {
          $table = $this-&gt;table('custom_quotes', ['id' =&gt; false, 'primary_key' =&gt; ['custom_quote_id']]);
          $table-&gt;addColumn('custom_quote_id', 'biginteger', ['identity' =&gt;true, 'signed' =&gt; false])
          -&gt;addColumn('account_id', 'biginteger', ['limit' =&gt; 20, 'null' =&gt; true])
          -&gt;addColumn('quote_type_id', 'integer', ['limit' =&gt; 11, 'null' =&gt; true])
          -&gt;addColumn('quote', 'string', ['limit' =&gt; 500, 'null' =&gt; true])
          -&gt;addColumn('selected', 'integer', ['limit' =&gt; 4, 'null' =&gt; true, 'default' =&gt; 1])
          -&gt;addForeignKey('account_id', 'accounts', 'account_id', array('delete'=&gt; 'NO_ACTION', 'update'=&gt; 'NO_ACTION'))
          -&gt;addForeignKey('quote_type_id', 'quote_types', 'quote_type_id', array('delete'=&gt; 'NO_ACTION', 'update'=&gt; 'NO_ACTION'))
          -&gt;create();
      }
  }
  </code></pre>
  
  <p>Accounts table</p>
  
  <pre><code>&lt;?php
  
  use Phinx\Migration\AbstractMigration;
  
  class MakeAccountsTable extends AbstractMigration
  {
      /**
       * Change Method.
       *
       * Write your reversible migrations using this method.
       *
       * More information on writing migrations is available here:
       * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
       *
       * The following commands can be used in this method and Phinx will
       * automatically reverse them when rolling back:
       *
       *    createTable
       *    renameTable
       *    addColumn
       *    renameColumn
       *    addIndex
       *    addForeignKey
       *
       * Remember to call "create()" or "update()" and NOT "save()" when working
       * with the Table class.
       */
      public function change()
      {
          $table = $this-&gt;table('accounts', ['id' =&gt; false, 'primary_key' =&gt; ['account_id']]);
          $table-&gt;addColumn('account_id', 'biginteger', ['identity' =&gt;true, 'signed' =&gt; false])
          -&gt;addColumn('css_user_guid', 'string', ['limit' =&gt; 40])
          -&gt;addColumn('state_id', 'integer', ['limit' =&gt; 11, 'null' =&gt; true])
          -&gt;addColumn('phone', 'string', ['limit' =&gt; 45, 'null' =&gt; true])
          -&gt;addColumn('street', 'string', ['limit' =&gt; 45, 'null' =&gt; true])
          -&gt;addColumn('city', 'string', ['limit' =&gt; 45, 'null' =&gt; true])
          -&gt;addColumn('zip', 'string', ['limit' =&gt; 45, 'null' =&gt; true])
          -&gt;addColumn('state', 'string', ['limit' =&gt; 45, 'null' =&gt; true])
          -&gt;addColumn('terms_of_service_accepted', 'boolean', ['limit' =&gt; 1, 'null' =&gt; true, 'default' =&gt; 0])
          -&gt;addColumn('quote', 'string', ['limit' =&gt; 300, 'null' =&gt; true])
          -&gt;addColumn('date_created', 'datetime', ['null' =&gt; true])
          -&gt;create();
      }
  }
  </code></pre>