Preloading problem that occurs only in test

Hello Fellas

So I came accross a wierd issue today that I would like to find the explanation

I have a record named Record1 with fields something: String and another record Record2
which has a field :record1_id which appears as

belongs_to :record1, Record1

in record definition

And what happends is that when i run the whole server application like iex -S mix phx.server I can list preload and everything. Problem is that when I tried to preload object2 with object1

Repo.all(Record2)
|> Repo.preload(:record_1)

within test I get an error. Complaining about missing fields.

** (Postgrex.Error) ERROR 42703 (undefined_column) column c0.something does not exist

same thing works as expected in normal mode (iex -S mix phx.server)

anybody faced similar issues to give me an explanation ?

Hi @nikolis,
Did you try to drop you’re db test before running your test suite?

MIX_ENV=test mix ecto.drop

Maybe a migration files you changed after the migration has run in test

4 Likes

Embarishing but that did it for my I completly overlloked the fact that I only had reset the database in the dev enviroment.