taguniversalmachine

taguniversalmachine

Phx.gen.auth generated code fails test with duplicate table "users" already exists

Hi

I am working through the Pragmatic Programmer “Programming Phoenix LiveView” book, and in the code generation section we run the phx.gen.auth generator, but when I run the tests I get:

12:37:30.010 [info] extension “citext” already exists, skipping
** (Postgrex.Error) ERROR 42P07 (duplicate_table) relation “users” already exists
(ecto_sql 3.7.2) lib/ecto/adapters/sql.ex:760: Ecto.Adapters.SQL.raise_sql_call_error/1
(elixir 1.12.1) lib/enum.ex:1553: Enum.“-map/2-lists^map/1-0-”/2
(ecto_sql 3.7.2) lib/ecto/adapters/sql.ex:852: Ecto.Adapters.SQL.execute_ddl/4
(ecto_sql 3.7.2) lib/ecto/migration/runner.ex:343: Ecto.Migration.Runner.log_and_execute_ddl/3
(ecto_sql 3.7.2) lib/ecto/migration/runner.ex:117: anonymous fn/6 in Ecto.Migration.Runner.flush/0
(elixir 1.12.1) lib/enum.ex:2356: Enum.“-reduce/3-lists^foldl/2-0-”/3
(ecto_sql 3.7.2) lib/ecto/migration/runner.ex:116: Ecto.Migration.Runner.flush/0
(ecto_sql 3.7.2) lib/ecto/migration/runner.ex:280: Ecto.Migration.Runner.perform_operation/3

I can run mix ecto.reset

% mix ecto.reset
The database for Pento.Repo has been dropped
The database for Pento.Repo has been created

13:39:18.491 [info] == Running 20220209071806 Pento.Repo.Migrations.CreateUsersAuthTables.change/0 forward

13:39:18.501 [info] execute “CREATE EXTENSION IF NOT EXISTS citext”

13:39:18.631 [info] create table users

13:39:18.669 [info] create index users_email_index

13:39:18.671 [info] create table users_tokens

13:39:18.679 [info] create index users_tokens_user_id_index

13:39:18.680 [info] create index users_tokens_context_token_index

13:39:18.733 [info] == Migrated 20220209071806 in 0.2s

but the test fails with the same error. I’m not sure how to diagnose this as everything is pretty much generated code. Any ideas?

Marked As Solved

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

If you’re getting the error with tests, you should drop the test database and then try again:

MIX_ENV=test mix ecto.drop
mix test

Last Post!

taguniversalmachine

taguniversalmachine

well ok, that was awesome, thank you!

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New

Other popular topics Top

grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54260 488
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New

We're in Beta

About us Mission Statement