(KeyError) key :source not found in: nil

i ran into this error while generating migrations;

mix ash_postgres.generate_migrations --name add_knowledge_base_tables                                                        ─╯
** (KeyError) key :source not found in: nil

If you are using the dot syntax, such as map.field, make sure the left-hand side of the dot is a map
    (ash_postgres 2.5.19) lib/migration_generator/migration_generator.ex:2942: anonymous fn/2 in AshPostgres.MigrationGenerator.check_constraints/1
    (elixir 1.18.3) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
    (ash_postgres 2.5.19) lib/migration_generator/migration_generator.ex:2937: anonymous fn/2 in AshPostgres.MigrationGenerator.check_constraints/1
    (elixir 1.18.3) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
    (ash_postgres 2.5.19) lib/migration_generator/migration_generator.ex:2889: AshPostgres.MigrationGenerator.do_snapshot/3
    (ash_postgres 2.5.19) lib/migration_generator/migration_generator.ex:2879: AshPostgres.MigrationGenerator.get_snapshots/2
    (elixir 1.18.3) lib/enum.ex:4442: Enum.flat_map_list/2
    (elixir 1.18.3) lib/enum.ex:4445: Enum.flat_map_list/2

this is the link to my github code; https://github.com/johnsseruwagi/travelix
@kamaroly and @zachdaniel

:thinking: my suspicion is that you have a field in a check constraint configuration somewhere that does not exist. Could you check those?

2 Likes

It looks like you’re trying to generate migrations for a lot of resources all at once - I’d suggest breaking it down a bit and going one-by-one, to see where the error occurs.

1 Like

Unfortunately I have read all the documentation about ash_postgres migration and there is no possible way for running a migration for a specific resource, however this is possible for a particular domain, so meaning I have to delete all my resources and start to build one by one as I run migration, this is very tedious to do and I will consider it as last option

thank you, the problem was in one of my file
instead of this

check_constraints do
       check_constraint :rating, "rating should be positive", check: "rating >= 0", message: "rating must be positive"
     end

i had this

check_constraints do
       check_constraint :rating_positive, "rating should be positive", check: "rating >= 0", message: "rating must be positive"
     end

so the constraint being generated was failing sing rating_positive is not an attribute in my table

thanks so much brother, i had to do this, fortunately i found the bug in one of my resources