# rails consoleでユーザーを削除したが、u.delete -\\u003e メールがまだ「使用中」である

**URL:** https://meta.discourse.org/t/deleted-user-with-rails-console-u-delete-email-still-taken/164868
**Category:** Bug
**Created:** [2020 年 9 月 22 日午後 12:24 UTC](https://meta.discourse.org/t/deleted-user-with-rails-console-u-delete-email-still-taken/164868 "2020-09-22T12:24:53Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Wille](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wille/32/194693_2.png) [@Wille](https://meta.discourse.org/u/Wille)
#### Post date: [2020 年 9 月 22 日午後 12:24 UTC](https://meta.discourse.org/t/deleted-user-with-rails-console-u-delete-email-still-taken/164868/1 "2020-09-22T12:24:53Z")

</div>

以前、管理者アカウントに割り当てていたメールアドレスがドメイン変更後に存在しなくなったため、メールアドレスを変更しようとしたのですが、古いメールアドレスへの確認が必要であるためできませんでした。

長い話の要約ですが、いくつかの操作を行い、いくつかのメールアドレスを変更し、別の管理者アカウントを作成し、コンソールを使用して2番目の管理者アカウントを削除しました。しかし、現在、2番目の管理者アカウントに割り当てていたメールアドレスを再利用することができません。

サポートかバグのどちらに分類すべきか迷っています。  
正直なところ、バックアップを使って復元することも可能ですが、その前に、これはバグでしょうか？完全なリセットやバックアップからの復元なしにこれを修正する方法はありますか？

---

<div class="post-metadata">

### Author: ![IAmGav](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/iamgav/32/235598_2.png) [@IAmGav](https://meta.discourse.org/u/IAmGav)
#### Post date: [2020 年 9 月 22 日午後 12:37 UTC](https://meta.discourse.org/t/deleted-user-with-rails-console-u-delete-email-still-taken/164868/2 "2020-09-22T12:37:54Z")

</div>

データエクスプローラープラグインをインストールすると、削除したいメールアドレスがまだ残っているテーブルを確認できます。

> [@Discourse Data Explorer](https://meta.discourse.org/t/data-explorer-plugin/32566):
>
> discourse2Summary Discourse [Data Explorer](https://meta.discourse.org/t/32566?silent=true) allows you to make SQL queries against your live database, allowing for up-to-the-minute stats reporting.open_bookInstall Guide This plugin is bundled with Discourse core. There is no need to install the plugin separately.information_source If you’re looking for examples or support for any custom queries, you can find lots of topics in our #Data & reporting category under the #sql-query tag. If there’s not one to suit your pa…

---

<div class="post-metadata">

### Author: ![Wille](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wille/32/194693_2.png) [@Wille](https://meta.discourse.org/u/Wille)
#### Post date: [2020 年 9 月 22 日午後 1:01 UTC](https://meta.discourse.org/t/deleted-user-with-rails-console-u-delete-email-still-taken/164868/3 "2020-09-22T13:01:16Z")

</div>

どのテーブル（複数可）を検索または削除するかを知る必要があります。異なるスキーマを持つ100以上のテーブルに対して、100以上の独自に作成されたクエリを手動で生成することを提案しているわけではない限り、これは不可欠です。

この投稿を「バグ」カテゴリに再分類していただければ幸いです。

---

<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: [2020 年 9 月 22 日午後 4:45 UTC](https://meta.discourse.org/t/deleted-user-with-rails-console-u-delete-email-still-taken/164868/4 "2020-09-22T16:45:27Z")

</div>

> [@Wille](#):
>
> 別の管理者アカウントを作成し、コンソールを使って 2 番目の管理者アカウントを削除しましたが、2 番目の管理者アカウントに割り当てていたメールアドレスを再利用できません。
> 
> これはサポートに該当するのか、バグに該当するのか迷っています。

これはおそらくバグではないようです。コンソールからユーザーを削除した方法によります。

コンソールから以下のように検索してみてください。

```plaintext
UserEmail.where(email: '<your_deleted_users_email>')

```

結果が返ってきた場合は、返された `user_id` でユーザーを検索してみてください。

```plaintext
User.find_by(id: <email_record_id>)

```

推測ですが、削除したユーザーにそのメールアドレスが割り当てられていたため、ユーザーは返されないでしょう。その場合、メールレコードに対して `destroy!` を呼び出すのは安全です。実行する前に、必ずサイトの最新のバックアップを取得してください。

もしそのメールが既存のユーザーに割り当てられている場合は、メールレコードを削除しないでください。

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [2020 年 9 月 22 日午後 4:58 UTC](https://meta.discourse.org/t/deleted-user-with-rails-console-u-delete-email-still-taken/164868/5 "2020-09-22T16:58:08Z")

</div>

> [@simon](#):
>
> コンソールからユーザーを削除する方法によって異なります。

コンソールからユーザーを削除するには、UserDestroyer を使用します。詳細は [Deleting Users in rails console - #2 by jomaxro](https://meta.discourse.org/t/deleting-users-in-rails-console/141540/2) を参照してください。

メモ：これを #howto:faq に変換する
