Dealing with the config is undefined Error in an Ash Database Migration
I recently created an Ash app, created the Ash domain and resources, and ran the mix ash.codegen
to create a database migration. When I ran the command, I got the following error message:
(UndefinedFunctionError) function ForumApp.Forum.config/0 is undefined or private
(forum_app 0.1.0) ForumApp.Forum.config()
(ash_postgres 2.4.12) lib/migration_generator/migration_generator.ex:160: AshPostgres.MigrationGenerator.snapshot_path/2
(ash_postgres 2.4.12) lib/migration_generator/migration_generator.ex:168: anonymous fn/2 in AshPostgres.MigrationGenerator.create_extension_migrations/2
(elixir 1.17.2) lib/enum.ex:1703: Enum."-map/2-lists^map/1-1-"/2
(elixir 1.17.2) lib/enum.ex:1703: Enum."-map/2-lists^map/1-1-"/2
(ash_postgres 2.4.12) lib/migration_generator/migration_generator.ex:53: AshPostgres.MigrationGenerator.generate/2
(mix 1.17.2) lib/mix/task.ex:495: anonymous fn/3 in Mix.Task.run_task/5
(elixir 1.17.2) lib/enum.ex:1703: Enum."-map/2-lists^map/1-1-"/2
I knew I made a mistake somewhere, but when I compared the code I wrote with the code from other Ash projects I made, I didn’t see any differences besides the name of the project.
After trying for a day to find the source of the problem, I asked a question about this problem on the Elixir Forum and was guided toward the cause of the problem and the solution.
The Cause of the Problem #
If you get this error when doing a database migration, check that the postgres
section of your Ash resource has the correct repo name.
My mistake was I passed the name of my Ash domain as the repo instead of the name of the repo.
postgres do
table "posts"
repo ForumApp.Forum
end
The solution #
Use the name of the repo instead of the name of the Ash domain.
postgres do
table "posts"
repo ForumApp.Repo
end