XF 2.2 Retain IDs on auto-increment column


Well-known member
I'm building an add-on and I'm going to need to import all of the old data into the add-on. However, the IDs of the data I'm importing needs to remain the same. I've already written the importer, and everything works fine, except the IDs are not retained. They're, obviously, starting at 1 and working their way up.

I can turn the auto-increment off, then back on after the import, but that requires me to do a few different add-on upgrades. I'd rather do it all at once, if possible.

So, my question is, is it possible to import the data, using the entity manager and retaining the IDs, but then having auto-increment remain on for any new data?
Dangit! I hate when I post a question then find the answer within minutes after. I think maybe posting the question sparks different ways of searching for the answer. Anyways, I figured this one out. 🤦‍♂️

For anyone else looking for a solution to this, here's how I did it.

$entity = \XF::em()->create('Vendor\AddOn:Entity');
$entity->set('entity_id', $oldEntityId, ['forceSet' => true]);

//Set the rest of the necessary entity values

Top Bottom