dwyl / learn-phoenix

:fire: Phoenix is the web framework without compromise on speed, reliability or maintainability! Don't settle for less. :rocket:
650 stars 45 forks source link

p.165 when attempting to run "mix ecto.migrate" getting error: (Postgrex.Error) ERROR 42P07 (duplicate_table): relation "videos" already exists #50

Closed nelsonic closed 7 years ago

nelsonic commented 7 years ago

image

nelson@local:rumbl Admin$ mix ecto.migrate

09:04:00.993 [info]  == Running Rumbl.Repo.Migrations.CreateVideo.change/0 forward

09:04:00.993 [info]  create table videos
** (Postgrex.Error) ERROR 42P07 (duplicate_table): relation "videos" already exists
    (ecto) lib/ecto/adapters/sql.ex:195: Ecto.Adapters.SQL.query!/5
    (ecto) lib/ecto/adapters/postgres.ex:86: anonymous fn/4 in Ecto.Adapters.Postgres.execute_ddl/3
    (elixir) lib/enum.ex:1623: Enum."-reduce/3-lists^foldl/2-0-"/3
    (ecto) lib/ecto/adapters/postgres.ex:86: Ecto.Adapters.Postgres.execute_ddl/3
    (ecto) lib/ecto/migration/runner.ex:98: anonymous fn/2 in Ecto.Migration.Runner.flush/0
    (elixir) lib/enum.ex:1623: Enum."-reduce/3-lists^foldl/2-0-"/3
    (ecto) lib/ecto/migration/runner.ex:96: Ecto.Migration.Runner.flush/0
    (stdlib) timer.erl:181: :timer.tc/2
    (ecto) lib/ecto/migration/runner.ex:27: Ecto.Migration.Runner.run/6
    (ecto) lib/ecto/migrator.ex:121: Ecto.Migrator.attempt/6
    (ecto) lib/ecto/migrator.ex:71: anonymous fn/4 in Ecto.Migrator.do_up/4
    (ecto) lib/ecto/adapters/sql.ex:615: anonymous fn/3 in Ecto.Adapters.SQL.do_transaction/3
    (db_connection) lib/db_connection.ex:1274: DBConnection.transaction_run/4
    (db_connection) lib/db_connection.ex:1198: DBConnection.run_begin/3
    (db_connection) lib/db_connection.ex:789: DBConnection.transaction/3
    (ecto) lib/ecto/migrator.ex:244: anonymous fn/4 in Ecto.Migrator.migrate/4
    (elixir) lib/enum.ex:1184: Enum."-map/2-lists^map/1-0-"/2
    (ecto) lib/mix/tasks/ecto.migrate.ex:84: anonymous fn/4 in Mix.Tasks.Ecto.Migrate.run/2
    (elixir) lib/enum.ex:651: Enum."-each/2-lists^foreach/1-0-"/2
    (elixir) lib/enum.ex:651: Enum.each/2
nelsonic commented 7 years ago

Out of impatience I deleted all tables in the database! and then the mix ecto.migrate worked: image

When I ran mix test I got: image

there are (were) two _create_video.exs migrations: image

They appear to be identical:

https://github.com/dwyl/learn-phoenix-framework/blob/f2a17a28c6efd8f8f47a68368db1e0c95dfd6855/rumbl/priv/repo/migrations/20170213071353_create_video.exs image

https://github.com/dwyl/learn-phoenix-framework/blob/f2a17a28c6efd8f8f47a68368db1e0c95dfd6855/rumbl/priv/repo/migrations/20170212214945_create_video.exs image

So I deleted one of them.

The migration works but getting an error ERROR 42P07 (duplicate_table): relation "videos" already exists when attempting to run the tests: image

nelsonic commented 7 years ago

This is an exceptionally frustrating error message because the debug log is utterly useless!! 😢 There is no indication as to where in the (my) code we are attempting to re-create the "videos" relation...! 😧

nelsonic commented 7 years ago

"solved" it by deleting all tables in the rumbl_test database and re-running mix test: at least now the tests run but one of them is failing:

image

jackcarlisle commented 7 years ago

This might have been an issue to do with not "rolling back" your duplicate migration. If you want to undo a migration you can call mix ecto.rollback which will completely remove it. You can also roll back to specific migrations using:

mix ecto.rollback -v [timestamp]

nelsonic commented 7 years ago

Googlededed for the error: no function clause matching in Ecto.build_assoc/3 foundeded: https://elixirforum.com/t/no-function-clause-matching-in-ecto-build-assoc-3/1123 which is exactly the error I am seeing. so now reading through the replies ... 👀

nelsonic commented 7 years ago

After a bit of digging found the answer on: https://forums.pragprog.com/forums/393/topics/14291 duplicate resources "/videos", VideoController in scope "/" and scope "/manage" of router.ex