作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我刚刚接触 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
做了一些建议,但是这也会放弃自动递增。我只是不知道怎么弄明白。
最佳答案
我终于找到了答案。我只是像这样使用 DB::statement
DB::statement('ALTER TABLE `journal` DROP PRIMARY KEY , ADD PRIMARY KEY ( `id` , `journal_date` , `no_ref` , `acc_id` ) ;');
我的问题解决了。
关于php - 如何在 laravel 迁移中使用 auto_increment 创建多个主键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23923148/
我是一名优秀的程序员,十分优秀!