bulldog_in_the_dream
Problems adding schema to existing context
I am trying to add a schema and repo functions to an existing context.
I run mix phx.gen.context ExistingContext NewSchema new_schema …
Phoenix picks up that I’m adding to an existing context and asks if I want to proceed, I say yes, everything seems to have been generated fine, I run the migrations. But when I try to compile I get the following error message:
Project.Context.Project.Context.Schema.struct/1 is undefined, cannot expand struct Project.Context.Project.Context.Schema
For some reason Phoenix seems to have duplicated the project/context path and is looking for the schema in a non-existing place. Anyone have an idea what is happening here?
EDIT: I now tried generating just the schema and add code in the context file manually, the problem is the same.
Most Liked Responses
achempion
bulldog_in_the_dream
We figured it out. We had a schema file inside our Project/Context folder with the same name as Project. When you add to an existing context the code that accesses the repo is added at the bottom of the file, i.e. below the line “alias Project.Context.Project”. For some reason that made Phoenix look in the wrong path. Moving the code above the “alias Project.Context.Project” line fixed it. Don’t know why though.








