1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PG::DuplicateTable: ERROR:を改善

Last updated at Posted at 2021-12-16

状況

マイグレーション時に下記のエラー表示がありました。

PG::DuplicateTable: ERROR:  relation "tasks" already exists/Users/****/task_app/db/migrate/20211216010101_create_tasks

環境

  • Rails 6.0.3
  • PostgreSQL 14.0

改善

冒頭のエラー文の通り、Tableが重複しているようなので下記の手順で重複分を削除しました。

DB内を確認

$ rails db

\dを入力して一覧表示

# \d

List of relations
Schema |         Name         |   Type   | Owner
--------+----------------------+----------+-------
public | ar_internal_metadata | table    | ****
public | schema_migrations    | table    | ****
public | tasks                | table    | ****
public | tasks_id_seq         | sequence | ****
(4 rows)

今回は"tasks"を削除すれば改善されるので、下記の通りdrop tableの後にtasks;を指定し実行。

# drop table tasks;

DROP TABLE

\dで再度確認してみます。

# \d

List of relations
Schema |         Name         | Type  | Owner
--------+----------------------+-------+-------
public | ar_internal_metadata | table | ****
public | schema_migrations    | table | ****
(2 rows)

今回の"tasks"が上手く削除されていました。

その後は通常どおりマイグレーションを実行すると改善されています。

$ rails db:migrate

参考

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?