问题
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?
回答1:
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)
回答2:
To change the AUTO_INCREMENT value on the table:
ALTER TABLE wp_postmeta AUTO_INCREMENT = 1000;
来源:https://stackoverflow.com/questions/14467577/how-to-autoincrement-starting-from-a-certain-number-offset