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?

Trending in Questions Top

lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
tj0
I’ve been following the steps here for the upgrade from 1.6 to 1.7 and it has gone relatively smoothly all the way till the phoenix_view ...
New
cgraham
Hi! What is currently the best library/method for parsing text and tabular data out of PDF files in Elixir or Erlang?
New
stefanchrobot
Hi, I need a way to handle data migrations in my application. I found an article by @wojtekmach about manual migrations: Automatic and ma...
New
stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
webofbits
Squid Mesh is an open source workflow automation runtime for Elixir applications. It is aimed at Phoenix and OTP apps that want to defin...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
kip
In 2021 I started a new library called Tempo with the objective of modelling time as a set of intervals - not as instants. In 2022 I gave...
New

We're in Beta

About us Mission Statement