title: unable to create a table in magento 2
body: <p>I'm trying to create a table using install schema but it throws the error given below
  Installing schema... SQLSTATE[HY000]: General error: 1005 Can't create table <code>magento</code>.<code>questionanswer</code> (errno: 150 "Foreign key constraint is incorrectly formed"), query was: CREATE
   TABLE IF NOT EXISTS <code>questionanswer</code> (
    <code>question_id</code> int NULL COMMENT 'Question ID' ,
    <code>answer_id</code> int NULL COMMENT 'Answer ID' ,
    PRIMARY KEY (<code>question_id</code>, <code>answer_id</code>),
    INDEX <code>QUESTIONANSWER_ANSWER_ID</code> (<code>answer_id</code>),
    CONSTRAINT <code>QUESTIONANSWER_QUESTION_ID_FAQQUESTION_QUESTION_ID</code> FOREIGN KEY (<code>question_id</code>) REFERENCES <code>faqquestion</code> (<code>question_id</code>) ON DELETE CASCADE,
    CONSTRAINT <code>QUESTIONANSWER_ANSWER_ID_FAQANSWER_ANSWER_ID</code> FOREIGN KEY (<code>answer_id</code>) REFERENCES <code>faqanswer</code> (<code>answer_id</code>) ON DELETE CASCADE
  ) COMMENT=' Question to answer Linkage Table' ENGINE=INNODB charset=utf8 COLLATE=utf8_general_ci.</p>
  
  <p>My code from installschema for tables are</p>
  
  <pre><code>        //      Creating Question table
      $table = $installer-&gt;getConnection()-&gt;newTable(
          $installer-&gt;getTable('faqquestion')
      )-&gt;addColumn(
          'question_id',
          \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
          null,
          ['nullable' =&gt; false, 'primary' =&gt; true],
          'Question ID'
      )-&gt;addColumn(
          'question',
          \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
          '2M',
          ['nullable' =&gt; true,'default' =&gt; null],
          'Question'
      )-&gt;addColumn(
          'question_identifier',
          \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
          255,
          ['nullable' =&gt; true],
          'Identifier'
      )-&gt;addColumn(
          'question_topic',
          \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
          255,
          ['nullable' =&gt; true],
          'Topic'
      )-&gt;addColumn(
          'question_sortorder',
          \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
          1,
          ['nullable' =&gt; false,'default' =&gt; 0],
          'SortOrder'
      )-&gt;addColumn(
          'question_status',
          \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
          1,
          ['nullable' =&gt; false,'default' =&gt; 0],
          'Question Status'
      )-&gt;addColumn(
          'question_visibility',
          \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
          1,
          ['nullable' =&gt; false,'default' =&gt; 0],
          'Question Visibility'
      )-&gt;addColumn(
          'question_tags',
          \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
          255,
          ['nullable' =&gt; true],
          'Tags'
      )-&gt;setComment(
          'Question Table'
      );
      $installer-&gt;getConnection()-&gt;createTable($table);
  
  
  
      //creating answer table
      $table = $installer-&gt;getConnection()-&gt;newTable(
          $installer-&gt;getTable('faqanswer')
      )-&gt;addColumn(
          'answer_id',
          \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
          null,
          ['nullable' =&gt; false, 'primary' =&gt; true],
          'Answer ID'
      )-&gt;addColumn(
          'answer',
          \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
          '2M',
          ['nullable' =&gt; true,'default' =&gt; null],
          'Answer'
      )-&gt;addColumn(
          'answer_likes',
          \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
          1,
          ['nullable' =&gt; false,'default' =&gt; 0],
          'Likes'
      )-&gt;addColumn(
          'answer_dislikes',
          \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
          1,
          ['nullable' =&gt; false,'default' =&gt; 0],
          'Dislikes'
      )-&gt;addColumn(
          'answer_author',
          \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
          255,
          ['nullable' =&gt; true],
          'Author'
      )-&gt;addColumn(
          'answer_status',
          \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
          1,
          ['nullable' =&gt; false,'default' =&gt; 0],
          'Answer Status'
      )-&gt;setComment(
          'Answer table'
      );
      $installer-&gt;getConnection()-&gt;createTable($table);
  
  //        queston and related answer table
      $table = $installer-&gt;getConnection()-&gt;newTable(
          $installer-&gt;getTable('questionanswer')
      )-&gt;addColumn(
          'question_id',
          \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
          null,
          ['nullable' =&gt; true, 'primary' =&gt; true],
          'Question ID'
      )-&gt;addColumn(
          'answer_id',
          \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
          null,
          ['nullable' =&gt; true, 'primary' =&gt; true],
          'Answer ID'
      )-&gt;addIndex(
          $installer-&gt;getIdxName('questionanswer', ['answer_id']),
          ['answer_id']
      )-&gt;addForeignKey(
          $installer-&gt;getFkName('questionanswer', 'question_id', 'faqquestion', 'question_id'),
          'question_id',
          $installer-&gt;getTable('faqquestion'),
          'question_id',
          \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
      )-&gt;addForeignKey(
          $installer-&gt;getFkName('questionanswer', 'answer_id', 'faqanswer', 'answer_id'),
          'answer_id',
          $installer-&gt;getTable('faqanswer'),
          'answer_id',
          \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
      )-&gt;setComment(
          ' Question to aNswer Linkage Table'
      );
      $installer-&gt;getConnection()-&gt;createTable($table);
  </code></pre>