How to AUTOINCREMENT starting from a certain numbe

2020-05-09 01:22发布

I am running an fgetcsv query to import a bunch of data from a CSV into WordPress.

I am wondering how I can start an auto increment from a certain number, for example, from 1000 onwards.

$import1="INSERT into wp_postmeta (meta_id,post_id,meta_key,meta_value) values(',',',','first_name','$data[1]')";

This is an example of the code. the meta_id should use a normal auto increment, but the post_id I want to start from a certain number.

How would I accomplish this?

2条回答
Ridiculous、
2楼-- · 2020-05-09 01:55

To set the starting value for an auto increment field, you can use alter table

ALTER TABLE wp_postmeta AUTO_INCREMENT = 1000;

As far as I know, it is not possible to have two auto incrementing fields on the same table in mysql, so you have to do it progamatically yourself (eg with a trigger)

查看更多
Luminary・发光体
3楼-- · 2020-05-09 02:01

To change the AUTO_INCREMENT value on the table:

ALTER TABLE wp_postmeta AUTO_INCREMENT = 1000;
查看更多
登录 后发表回答