title: Laravel seed table with composite primary key
body: <p>I need to make a table with a composite primary key. I've been looking at multiple options to solve the problem to create an AUTO_INCREMENT field along with some other fields, and make them a composite primary key, but eventually I succeeded by doing it like this;</p>
  
  <pre><code>class CreateSpecificationTable extends Migration {
  
      public function up()
      {
          Schema::create('specification', function(Blueprint $table){
              $table-&gt;increments('specificationID');
              $table-&gt;integer('categoryID', false, true);
              $table-&gt;string('name', 100);
  
              $table-&gt;dateTime('created_at');
              $table-&gt;dateTime('updated_at')-&gt;nullable()-&gt;default(null);
              $table-&gt;dateTime('deleted_at')-&gt;nullable()-&gt;default(null);
  
              $table-&gt;foreign('categoryID')-&gt;references('categoryID')-&gt;on('categories');
          });
  
          DB::unprepared('ALTER TABLE specification DROP PRIMARY KEY, ADD PRIMARY KEY(specificationID, categoryID, name)');
      }
  </code></pre>
  
  <p>The model for this table is pretty simple:</p>
  
  <pre><code>class Specification extends Eloquent {
  
      protected $table = 'specification';
      protected $primaryKey = array('specificationID', 'categoryID', 'name');
  }
  </code></pre>
  
  <p>And then the seeder looks like this:</p>
  
  <pre><code>class SpecificationSeeder extends Seeder {
  
      public function run()
      {
          Specification::create(array(
          'categoryID'=&gt;1,
          'name'=&gt;'size',
          ));
  
          Specification::create(array(
          'categoryID'=&gt;2,
          'name'=&gt;'resolution',
          ));
  
          Specification::create(array(
          'categoryID'=&gt;1,
          'naam'=&gt;'connection',
          ));
      }
  }
  </code></pre>
  
  <p>However, when I run the <code>php artisan db:seed</code> command from CMD, I get the following error:</p>
  
  <pre><code>[ErrorException]
  PDO::lastInsertId() expects parameter 1 to be string, array given
  </code></pre>
  
  <p>The strange thing is that I've built a lot of other tables in this app already this way, but this is the first one where the <code>protected $primaryKey</code> in the model consists of an array with fields, rather than having one single primary key. </p>
  
  <p>Also, despite giving this error, the first 'seed' does get added in the database, but none after. </p>