eloquent-versioning icon indicating copy to clipboard operation
eloquent-versioning copied to clipboard

Multiple primary key

Open ghost opened this issue 7 years ago • 2 comments

Syntax error or access violation: 1068 Multiple prima ry key defined (SQL: alter table mytable_version add primary key mytable_version_version_primary(version ))

with code:

  Schema::create('mytable_version', function(Blueprint $table) {
            $table->integer('ref_id')->primary();
            $table->integer('version')->primary();
            //add versionable columns
            $table->timestamps();
            $table->softDeletes();
        });

ghost avatar Mar 25 '18 08:03 ghost

Hello @AceWT,

This should fix your issue:

Schema::create('mytable_version', function(Blueprint $table) {
	$table->integer('ref_id');
	$table->integer('version');
	//add versionable columns
	$table->timestamps();
	$table->softDeletes();
	
	$table->primary(['ref_id', 'version']);
});

crashkonijn avatar May 23 '18 21:05 crashkonijn

The README is updated accordingly in #20...

danhunsaker avatar Aug 20 '18 10:08 danhunsaker