dwyl / phoenix-ecto-append-only-log-example

📝 A step-by-step example/tutorial showing how to build a Phoenix (Elixir) App where all data is immutable (append only). Precursor to Blockchain, IPFS or Solid!
GNU General Public License v2.0
78 stars 7 forks source link

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

Closed nelsonic closed 5 years ago

nelsonic commented 5 years ago

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 commented 5 years ago

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 commented 4 years ago

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 commented 1 year ago

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

nelsonic commented 1 year ago

@jbosse stoked you found it helpful. 🎉