bulldog_in_the_dream

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.

First Post!

achempion

achempion

Could you please elaborate on shell command you are running to generate context with exact names.

The error trace would definitely help us to better understand your issue.

Thank you.

Most Liked

achempion

achempion

It was because of alias structure. I’ve fixed it for contexts, looks like we should fix it for a schema too. Thank you for a feedback.

bulldog_in_the_dream

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.

Where Next?

Popular in Questions Top

Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31525 112
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement