<p>If the <code>UserModel</code> contains a user ID, then the existing user will be <em>updated</em>.</p>

<p>If the <code>UserModel</code> does not contain a user ID, then a new user will be <em>created</em>.</p>

<p>Either way, the <code>UserModel</code> will contain an ID after being saved. Since models in PHP are passed by reference, the ID will get set automatically for new users.</p>

CC BY-SA 3.0
2016-09-29T18:30:34.543Z
Thanks for the reply, but that's not the question. I want a newly created user to have exactly the same ID as it was in the previous database.
Tibor Szasz
CC BY-SA 3.0
2016-09-29T19:13:36.970Z
Ah, that was not clear in the original question.
Lindsey D
CC BY-SA 3.0
2016-09-29T19:14:32.730Z
And if I guess right it's not doable?
Tibor Szasz
CC BY-SA 3.0
2016-09-29T19:15:19.307Z
It's probably doable, but complicated. I'll let someone else take a shot at answering that.
Lindsey D
CC BY-SA 3.0
2016-09-29T19:18:46.017Z
I think I'll do a surgical fix: add back the new user ID-s to the old tables and export them with the fresh ID-s :) Ugly, but only needs to be done once.
Tibor Szasz
CC BY-SA 3.0
2016-09-29T17:43:10.760Z
2016-09-29T17:43:10.760Z
Lindsey D
<p>Is it possible to use the saveUser method to import users with an existing ID?</p>

<pre><code>craft()-&gt;users-&gt;saveUser($userModel)
</code></pre>

<p>I need to import 2000+ users and when doing so, I need to make sure that their old ID doesn't change after inserted, because I need to import other tables too and match them based on that.</p>

<p>The excellent import plugin tries to update the users instead of creating new ones when I tell it to import the ID as well. I'm not sure if that's intended behavior or a bug.</p>

<import><plugin-import>
Import users with specific ID
# Import users with specific ID

(Asked by: username_0 on 2016-09-29)

Is it possible to use the saveUser method to import users with an existing ID?
craft()->users->saveUser($userModel)

I need to import 2000+ users and when doing so, I need to make sure that their old ID doesn't change after inserted, because I need to import other tables too and match them based on that.
The excellent import plugin tries to update the users instead of creating new ones when I tell it to import the ID as well. I'm not sure if that's intended behavior or a bug.

**Tags:** import, plugin-import

---

## 1 answers

### Answer by username_1 on 2016-09-29. Score: 1

If the `UserModel` contains a user ID, then the existing user will be *updated*.

If the `UserModel` does not contain a user ID, then a new user will be *created*.

Either way, the `UserModel` will contain an ID after being saved. Since models in PHP are passed by reference, the ID will get set automatically for new users.

> **Comments:**
> **username_0**: Thanks for the reply, but that's not the question. I want a newly created user to have exactly the same ID as it was in the previous database.  
> **username_1**: Ah, that was not clear in the original question.  
> **username_0**: And if I guess right it's not doable?  
> **username_1**: It's probably doable, but complicated. I'll let someone else take a shot at answering that.  
> **username_0**: I think I'll do a surgical fix: add back the new user ID-s to the old tables and export them with the fresh ID-s :) Ugly, but only needs to be done once.  

---

