I have an issue with Oban package. ** (KeyError) key :migrator not found

Running 20240305070930 MyApp.Repo.Migrations.AddObanJobsTable.up/0 forward
** (KeyError) key :migrator not found

Here is my implementation

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

  def up do
    Oban.Migration.up(opts: [repo: MyApp.Repo])
  end

end

Hello,

first questions:
Have you installed the Oban dependency via mix deps.get?
and how does your oban config looks like?

In mix.exs I have {:oban, “~> 2.11”}

In config.exs I have this

config :my_app, Oban,
  queues: [default: 10],
  repo: MyApp.Repo

Hi there,

In your original message you are referencing a :repo module with the name of V8Bet.Repo, but in your later message you’re saying that your config.exs references MyApp.Repo. Is this correct? Are you perhaps mixing some names, either in your code or in the examples you’re providing us?

In any case, the error you are seeing most likely stems from Oban not being able to determine how to run the migrations for you. More specifically, Oban doesn’t seem to be able to determine that you have either Postgrex (for PostgreSQL) or EctoSQLite3 (for SQLite3) available and configured for your Repo, and then tries to look up a :migrator option as a fallback. While this could be due to some mix-up in a configuration somewhere (the confused names I mentioned above), it’s at least equally likely that something in your project setup isn’t quite as expected.

How have you set up your project in general? Which database are you using, and which Elixir dependency are you using to communicate with it? Note that while Ecto is used to run the migrations, Ecto alone doesn’t enable database connectivity.

For sake of reference, you can can try to create a straightforward, functional Oban setup by first creating a fresh Phoenix [1] project through mix phx.new yourprojectname (see Phoenix guides for more if you get stuck), and then following the steps in Installation — Oban v2.17.6 to add Oban to that project. Perhaps this can help you backtrack on what’s missing in your project.

([1] Phoenix is not required at all by Oban, but running the project generator from Phoenix allows for an easy, repeatable setup where Ecto and other dependencies are properly configured for you).

Thanks juhalehtonen for reaching out.

Here is my database configuration in dev.exs

# Configure your database
config :my_app, MyApp.Repo,
  username: "root",
  password: "",
  hostname: "localhost",
  database: "db_dev",
  pool_size: 10,
  adapter: Ecto.Adapters.MySQL

I was trying out Oban in an application named my_app. Indeed I had a line of code copied from a separate project named V8Bet.

Anyway, the issue persists only while running the Oban migrations, other migrations work fine.

Thank you for sharing the Repo configuration. That clears things up.

Unfortunately, Oban doesn’t support MySQL (see the Requirements heading) out of the box, and I’m not aware of any third-party adapters for it, either.

There has been a discussion about this in this Oban GitHub issue if you wish to learn more about why MySQL is not supported at this time.

1 Like

Thanks for help :slight_smile:

1 Like