Testing with ecto enabled elixir app


I am new to Elixir and this forum (my first post). I have a question around testing a elixir app which I wrote for authenticating a user and a test around it. Please see below, the test execution log:

$ MIX_ENV=test mix do ecto.drop, ecto.create, ecto.migrate, test

The database for Autht.Repo has been dropped
The database for Autht.Repo has been created
[<<<<<No output to show migration has run>>>>>>]

05:17:08.807 [debug] QUERY OK db=1.1ms
begin []

05:17:08.817 [debug] QUERY ERROR db=0.0ms
INSERT INTO "users" ("auth_scheme","first_name","last_name","primary_email","primary_mobile","state","id") VALUES ($1,$2,$3,$4,$5,$6,$7) [1, "firstname", "lastname", "firstname@lastname.com", "+1 8885551212", "created", <<15, 60, 206, 223, 220, 203, 78, 78, 138, 137, 157, 217, 58, 182, 212, 255>>]

05:17:08.817 [debug] QUERY OK db=0.2ms
rollback []

  1) test Create a user Create user: firstname@lastname.com (AuthtTest)
     ** (Postgrex.Error) ERROR 42P01 (undefined_table) relation "users" does not exist   <- I am not able to get past this error

         query: INSERT INTO "users" ("auth_scheme","first_name","last_name","primary_email","primary_mobile","state","id") VALUES ($1,$2,$3,$4,$5,$6,$7)
     code: output = Autht.Accounts.create_user(user)
       (ecto_sql) lib/ecto/adapters/sql.ex:624: Ecto.Adapters.SQL.raise_sql_call_error/1
       (ecto) lib/ecto/repo/schema.ex:651: Ecto.Repo.Schema.apply/4
       (ecto) lib/ecto/repo/schema.ex:264: anonymous fn/15 in Ecto.Repo.Schema.do_insert/3
       (ecto) lib/ecto/repo/schema.ex:917: anonymous fn/3 in Ecto.Repo.Schema.wrap_in_transaction/6
       (ecto_sql) lib/ecto/adapters/sql.ex:820: anonymous fn/3 in Ecto.Adapters.SQL.checkout_or_transaction/4
       (db_connection) lib/db_connection.ex:1355: DBConnection.run_transaction/4
       test/autht_test.exs:10: (test)

I followed the steps in this thread How to set up the testing environment for a library that uses Ecto? to enable testing for the project

I am not using async: true

Thanks for your attention and assistance!

1 Like

Welcome to the forum! Judging from the error you ran into it looks like you might be missing a migration for the users table. If you do have one can you show it?

The issue was resolved by deleting the _build directory as mentioned by a post in this forum and relogin to the session (to clean up the exported shell variables).

Finally received a

   __meta__: #Ecto.Schema.Metadata<:loaded, "users">...}