Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR 42P07 (duplicate_table) relation "addresses" already exists #25

Closed
nelsonic opened this issue Apr 23, 2019 · 4 comments
Closed

ERROR 42P07 (duplicate_table) relation "addresses" already exists #25

nelsonic opened this issue Apr 23, 2019 · 4 comments

Comments

@nelsonic
Copy link
Member

While attempting to run the tests on localhost I got the following error:
image

Generated append app
[debug] QUERY OK source="schema_migrations" db=2.8ms
SELECT s0."version"::bigint FROM "schema_migrations" AS s0 FOR UPDATE []
[info] == Running 20180912142549 Append.Repo.Migrations.CreateAddresses.change/0 forward
[info] create table addresses
** (Postgrex.Error) ERROR 42P07 (duplicate_table) relation "addresses" already exists
    (ecto_sql) lib/ecto/adapters/sql.ex:595: Ecto.Adapters.SQL.raise_sql_call_error/1
    (elixir) lib/enum.ex:1314: Enum."-map/2-lists^map/1-0-"/2
    (ecto_sql) lib/ecto/adapters/sql.ex:682: Ecto.Adapters.SQL.execute_ddl/4

Someone who has only just cloned the repo and installed the deps is unlikely to see this error because they won't have a duplicate project in the same namespace the way I do ...
https://github.com/nelsonic/append-only-log-ex

I need to DROP the database and re-create it.

@nelsonic
Copy link
Member Author

Run the following commands in your terminal:

psql -U postgres -c 'DROP DATABASE IF EXISTS append_dev;'
psql -U postgres -c 'DROP DATABASE IF EXISTS append_test;'
mix ecto.create
mix test
MIX_ENV=test mix cover

You should see:
image

i.e. tests pass.
(I was making sure everything was working on localhost before tackling #17 ... 😉)

@nelsonic
Copy link
Member Author

nelsonic commented May 22, 2020

A year later, I'm seeing the same error in a different project and I'm grateful to my past self for creating this issue with the solution. (first result on Google in incognito) 😻
In Phoenix 1.5.1 it's just:

psql -U postgres -c 'DROP DATABASE IF EXISTS app_dev;'
psql -U postgres -c 'DROP DATABASE IF EXISTS app_test;'
mix test

Because now the mix test includes:

test: ["ecto.create --quiet", "ecto.migrate", "test"]

@jbosse
Copy link

jbosse commented Sep 26, 2022

I'm grateful to your past self for creating this issue, too, @nelsonic

@nelsonic
Copy link
Member Author

@jbosse stoked you found it helpful. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants