种子表与自动增量字段为零

时间:2016-06-16 16:15:04

标签: php mysql laravel-5 laravel-seeding

我为表创建了一个播种器,我尝试插入的第一条记录的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'));

1 个答案:

答案 0 :(得分: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'));
相关问题