# Changing custom user field ID#

**URL:** https://meta.discourse.org/t/changing-custom-user-field-id/86323
**Category:** Support
**Created:** [April 27, 2018, 5:59pm UTC](https://meta.discourse.org/t/changing-custom-user-field-id/86323 "2018-04-27T17:59:18Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Denis\_Heraud](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/denis_heraud/32/119623_2.png) [@Denis\_Heraud](https://meta.discourse.org/u/Denis_Heraud)
#### Post date: [April 27, 2018, 5:59pm UTC](https://meta.discourse.org/t/changing-custom-user-field-id/86323/1 "2018-04-27T17:59:18Z")

</div>

We had our webmaster adjust our SSO to pass data to some custom user fields. Sadly he didn’t assign them the right field ID’s. Is there any way that I, on my end, can change our custom user field ID’s in (or out) of Discourse?

I tried deleting all of our user fields and starting over thinking they would reset and start at 1, but unfortunately they start at 6 instead (since I had previously created 5 user fields).

i.e. `"user_fields":[{"id":6,"name":"Membership Type","description":"Membership Type"...`

EDIT: On a side note, why isn’t this information visible in the Admin interface? If I’m creating a bunch of user fields, how would I even know what their ID is in the first place? The 1,2,3,4… convention only really works if you a) never delete a user field; and b) never move a user field up or down.

EDIT 2: Maybe these can be changed through Rails?

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [April 30, 2018, 1:38pm UTC](https://meta.discourse.org/t/changing-custom-user-field-id/86323/3 "2018-04-30T13:38:27Z")

</div>

Why do you need the `user_fied` id for?

---

<div class="post-metadata">

### Author: ![Denis\_Heraud](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/denis_heraud/32/119623_2.png) [@Denis\_Heraud](https://meta.discourse.org/u/Denis_Heraud)
#### Post date: [April 30, 2018, 1:39pm UTC](https://meta.discourse.org/t/changing-custom-user-field-id/86323/4 "2018-04-30T13:39:05Z")

</div>

> [@zogstrip](#):
>
> Why do you need the user\_fied id for?

How else would I direct values from the SSO payload unless I knew what the field ID’s were?

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [April 30, 2018, 1:47pm UTC](https://meta.discourse.org/t/changing-custom-user-field-id/86323/5 "2018-04-30T13:47:21Z")

</div>

Right. I’m not familiar with that part of the code.

I agree that if we’re using the id to store their value, it should be visible somewhere.

As for the original question, you’ll have to reset the counter with some SQL

```sql
ALTER SEQUENCE user_fields_id_seq RESTART WITH 1;

```

---

<div class="post-metadata">

### Author: ![Denis\_Heraud](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/denis_heraud/32/119623_2.png) [@Denis\_Heraud](https://meta.discourse.org/u/Denis_Heraud)
#### Post date: [April 30, 2018, 2:23pm UTC](https://meta.discourse.org/t/changing-custom-user-field-id/86323/6 "2018-04-30T14:23:45Z")

</div>

> [@zogstrip](#):
>
> As for the original question, you’ll have to reset the counter with some SQL
> 
> ALTER SEQUENCE user\_fields\_id\_seq RESTART WITH 1;

Thank you @zogstrip ! Now would that reset the counter for existing fields, or subsequently created fields?

I presume I would have to delete my fields, run the command, and recreate them in the right order?

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [April 30, 2018, 2:24pm UTC](https://meta.discourse.org/t/changing-custom-user-field-id/86323/7 "2018-04-30T14:24:35Z")

</div>

That’ll reset the counter on the table. So it will only be used for subsequently created fields.

---

<div class="post-metadata">

### Author: ![Denis\_Heraud](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/denis_heraud/32/119623_2.png) [@Denis\_Heraud](https://meta.discourse.org/u/Denis_Heraud)
#### Post date: [April 30, 2018, 2:57pm UTC](https://meta.discourse.org/t/changing-custom-user-field-id/86323/8 "2018-04-30T14:57:33Z")

</div>

> [@zogstrip](#):
>
> That’ll reset the counter on the table. So it will only be used for subsequently created fields.

Just did it and it worked perfectly! Many thanks!

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [October 6, 2020, 12:24am UTC](https://meta.discourse.org/t/changing-custom-user-field-id/86323/9 "2020-10-06T00:24:12Z")

</div>


