Trying to build an API using Phoenix v1.3 following this tutorial:
https://dreamconception.com/tech/phoenix-full-fledged-api-in-five-minutes
(made sure to follow each step to the letter)
When I attempt to run mix ecto.setup
I get the following error:
Compiling 17 files (.ex)
== Compilation error on file lib/myapp/users/users.ex ==
** (CompileError) lib/myapp/users/users.ex:65: Myapp.Users.User.__struct__/0 is undefined, cannot expand struct Myapp.Users.User
(stdlib) lists.erl:1354: :lists.mapfoldl/3
lib/myapp/users/users.ex:65: (module)
(stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
(elixir) lib/kernel/parallel_compiler.ex:117: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/1
The lib/myapp/users/users.ex
is quite big: https://github.com/nelsonic/phoenix-api-example/blob/master/lib/myapp/users/users.ex#L65
Complete code on GitHub: https://github.com/nelsonic/phoenix-api-example
Any help debugging it would be much appreciated.
So there are a few things that I'm noticing:
You've named your context after your record. You should name your context after the idea the records are a part of. Something like Authentication
or Account
Building off of #1, in a Phoenix 1.3 app where you have an Account
context, you might have user records associated with that context. In that case you'd have Myapp.Account.Users defined in lib/myapp/account/users.ex. This is where your struct would come from.
I think how you've ended up here, is that the context is named the same as your records and that's causing some confusion. On line 9 of your Users
context you're aliasing Myapp.Users.User
but that module is never defined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With