title: How to create composite primary key by using Migration in Yii2?
body: <p>I tried to run <code>yii migrate</code>, but it showed the following error:</p>
  
  <pre><code>create table news-cate ...Exception: SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key
  The SQL being executed was: CREATE TABLE `news-cate` (
          `news-id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
          `cate-id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>class m150821_083020_create_newscate_table extends Migration
  {
      public function safeUp()
      {
          $this-&gt;createTable('news-cate', [
              'news-id' =&gt; $this-&gt;primaryKey(),
              'cate-id' =&gt; $this-&gt;primaryKey(),
          ]);
          $this-&gt;addForeignKey("fk_news_cate_nid", "news-cate", "news-id", "news", "id", "RESTRICT", "CASCADE");
          $this-&gt;addForeignKey("fk_news_cate_cid", "news-cate", "cate-id", "category", "id", "RESTRICT", "CASCADE");
      }
  
      public function safeDown()
      {
          echo "m150821_083020_create_newscate_table cannot be reverted.\n";
          $this-&gt;dropTable("news-cate");
          return false;
      }
  }
  </code></pre>
  
  <p>So how to create composite primary key by using Migration in Yii2?</p>