"function Oban.Migrations.V01.up/1 is undefined" during Oban migration

I’m currently exploring Phoenix and figured I’d try out setting up Oban to get an idea of how that works. I followed the instructions on the GitHub/Hexdocs page, but I’m running into an error during the migration for the setup, which I seem to be the only one getting, because Googling it hasn’t yielded me any results so far.

So, to summarize, I took the steps as listed in the docs.

Add the dependency:

def deps do
    {:oban, "~> 2.4.3"}

Get the dependencies:

mix deps.get

Generate the migration:

mix ecto.gen.migration add_oban_jobs_table

Set up the migration:

defmodule MovieDatabase.Repo.Migrations.AddObanJobsTable do
  use Ecto.Migration

  def up do

  def down do
    Oban.Migrations.down(version: 1)

Run the migration, which is where the error occurs:

mix ecto.migrate

This is the trace:

09:43:13.136 [info]  == Running 20210213083101 MovieDatabase.Repo.Migrations.AddObanJobsTable.up/0 forward

09:43:13.152 [debug] QUERY OK db=1.5ms
SELECT description
FROM pg_class
LEFT JOIN pg_description ON pg_description.objoid = pg_class.oid
LEFT JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace
WHERE pg_class.relname = 'oban_jobs'
AND pg_namespace.nspname = 'public'
** (UndefinedFunctionError) function Oban.Migrations.V01.up/1 is undefined (module Oban.Migrations.V01 is not available)
    (oban 2.4.3) lib/oban/migrations.ex:157: anonymous fn/4 in Oban.Migrations.change/3
    (elixir 1.11.2) lib/enum.ex:3449: Enum.reduce_range_inc/4
    (oban 2.4.3) lib/oban/migrations.ex:152: Oban.Migrations.change/3
    (ecto_sql 3.5.3) lib/ecto/migration/runner.ex:279: Ecto.Migration.Runner.perform_operation/3
    (stdlib 3.14) timer.erl:166: :timer.tc/1
    (ecto_sql 3.5.3) lib/ecto/migration/runner.ex:25: Ecto.Migration.Runner.run/8
    (ecto_sql 3.5.3) lib/ecto/migrator.ex:349: Ecto.Migrator.attempt/8
    (ecto_sql 3.5.3) lib/ecto/migrator.ex:249: anonymous fn/5 in Ecto.Migrator.do_up/5
    (ecto_sql 3.5.3) lib/ecto/migrator.ex:331: anonymous fn/3 in Ecto.Migrator.run_maybe_in_transaction/6
    (ecto_sql 3.5.3) lib/ecto/adapters/sql.ex:1027: anonymous fn/3 in Ecto.Adapters.SQL.checkout_or_transaction/4
    (db_connection 2.3.1) lib/db_connection.ex:1444: DBConnection.run_transaction/4
    (ecto_sql 3.5.3) lib/ecto/migrator.ex:330: Ecto.Migrator.run_maybe_in_transaction/6
    (elixir 1.11.2) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
    (elixir 1.11.2) lib/task/supervised.ex:35: Task.Supervised.reply/5
    (stdlib 3.14) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

Now, I may be missing something really obvious here, but since Google isn’t giving me anything useful and I’m unsure what to do with this error, I thought I’d ask.

The GitHub page does mention the following:

Note About Releases

If you are using releases you may see Postgrex errors logged during your initial deploy (or any deploy requiring an Oban migration). The errors are only temporary! After the migration has completed each queue will start producing jobs normally.

However, I’m not (as far as I’m aware) using Releases, so I figured this is not the issue (it’s also not a Postgrex error).

In case anyone runs into this: I just removed the dependency (and did mix deps.clean --unused) and then added it again (and of course mix deps.get). The migration then magically worked.

1 Like