# Is it possible to change users SSO's external\_id after a DB migration?

**URL:** https://meta.discourse.org/t/is-it-possible-to-change-users-ssos-external-id-after-a-db-migration/62099
**Category:** Support
**Created:** [2017 年 5 月 4 日午前 10:57 UTC](https://meta.discourse.org/t/is-it-possible-to-change-users-ssos-external-id-after-a-db-migration/62099 "2017-05-04T10:57:02Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![caub](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/caub/32/121044_2.png) [@caub](https://meta.discourse.org/u/caub)
#### Post date: [2017 年 5 月 4 日午前 10:57 UTC](https://meta.discourse.org/t/is-it-possible-to-change-users-ssos-external-id-after-a-db-migration/62099/1 "2017-05-04T10:57:02Z")

</div>

First I had issues with the external\_id field on SSO, because they were all initially strings of length 16, and later I stored 24chars strings, but it completely messed up, you could get logged under a different user, it seems it cropped the external\_id length, but that was hard to debug.

So I make sure to keep external\_id with the same length, it’s not really practical, why not using a TEXT column type for it?

And my question is also, can I update the external\_id of existing users, after doing a DB migration on my external site that provides SSO? and allow those users to keep their existing discourse profile when they’ll log in

Thanks for that good work

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [2017 年 5 月 4 日午後 3:08 UTC](https://meta.discourse.org/t/is-it-possible-to-change-users-ssos-external-id-after-a-db-migration/62099/2 "2017-05-04T15:08:54Z")

</div>

The easiest way might be to simply delete all external IDs – when your users try to sign in again, Discourse will use the email address to find the right account. (This won’t work if the users change their email address in the meantime!)

---

<div class="post-metadata">

### Author: ![caub](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/caub/32/121044_2.png) [@caub](https://meta.discourse.org/u/caub)
#### Post date: [2017 年 5 月 4 日午後 3:41 UTC](https://meta.discourse.org/t/is-it-possible-to-change-users-ssos-external-id-after-a-db-migration/62099/3 "2017-05-04T15:41:17Z")

</div>

Thanks a lot,

So I’ll try to do a UPDATE user\_table\_name SET external\_id=NULL, in DB 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: [2019 年 6 月 1 日午後 3:44 UTC](https://meta.discourse.org/t/is-it-possible-to-change-users-ssos-external-id-after-a-db-migration/62099/4 "2019-06-01T15:44:44Z")

</div>



---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [2019 年 6 月 1 日午後 7:39 UTC](https://meta.discourse.org/t/is-it-possible-to-change-users-ssos-external-id-after-a-db-migration/62099/5 "2019-06-01T19:39:55Z")

</div>

The `external_id` saved to the `single_sign_on_records` table. You can delete all records from this table by entering the rails console and running

```ruby
SingleSignOnRecord.destroy_all

```

As long as you are not setting `require_activation` to `true` in the SSO payload, after deleting your site’s SSO records, new SSO records will be created for your users based on their email address when they login with SSO.

---

<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: [2022 年 10 月 27 日午前 12:33 UTC](https://meta.discourse.org/t/is-it-possible-to-change-users-ssos-external-id-after-a-db-migration/62099/6 "2022-10-27T00:33:53Z")

</div>



---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [2022 年 10 月 27 日午後 8:26 UTC](https://meta.discourse.org/t/is-it-possible-to-change-users-ssos-external-id-after-a-db-migration/62099/7 "2022-10-27T20:26:45Z")

</div>


