0

我为一个表创建了一个播种器,我尝试插入的第一条记录的 ID=0。ID 是一个自动增量字段,当它被插入时,我检查它的 ID 并且它是 1 而不是 0,所以当我尝试创建 ID 为 1 的记录时,播种器会在下一行中断。

如何插入多条记录,第一条的 ID 为 0?

这是我的代码:

DB::table('payment_status')->delete();
DB::table('payment_status')->insert(array('id' => '0', 'name' => 'Initial'));
DB::table('payment_status')->insert(array('id' => '1', 'name' => 'Payment successful, Waiting for Processing'));
4

1 回答 1

1

由于 Uueerdo 的建议,我已经能够得到这个工作,在插入后更新行:

DB::table('payment_status')->delete();
DB::table('payment_status')->insert(array('id' => '0', 'name' => 'Initial'));
// id zero does not work
DB::unprepared("UPDATE payment_status SET id=0");
DB::table('payment_status')->insert(array('id' => '1', 'name' => 'Payment successful, Waiting for Processing'));
于 2016-06-16T16:38:46.283 回答