【发布时间】:2014-05-28 22:51:40
【问题描述】:
我刚接触 Laravel。我在进行迁移时遇到问题。我的Schema是这样的
public function up()
{
Schema::create('journal', function($table){
$table->increments('id');
$table->timestamp('journal_date');
$table->string('no_ref',25);
$table->string('acc_id', 10);
$table->string('description', 100);
$table->integer('debet')->default(0);
$table->integer('kredit')->default(0);
$table->primary(array('journal_date', 'no_ref', 'acc_id'));
});
}
然后在运行 PHP artisan migrate 时出现错误
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1068 Multiple primary key
defined (SQL: alter table `journal` add primary key
journal_journal_date_no_ref_acc_id_primary(`journal_date`,
`no_ref`, `acc_id`))
我向drop primary 提出了一些建议,但这也会降低自动增量。就是不知道怎么弄。
【问题讨论】:
-
不不不,不一样。这种情况不是外键而是多个主键,包括auto_increment