Elixir Phoenix项目种子数据填充报错,求解决方案
解决Phoenix种子数据编译错误:App.Items.__struct__未定义
错误根源:你用
mix phx.gen.json Items Item items name:string生成的Schema模块是App.Items.Item,而非App.Items。代码里写错了模块名,导致编译时找不到对应的struct定义。修复代码:修改
priv/repo/seeds.exs中的插入语句,把模块名修正为正确的App.Items.Item:
App.Repo.insert!(%App.Items.Item{name: "we are the world"})
- 验证操作:
- 执行种子数据命令:
mix run priv/repo/seeds.exs - 可通过Phoenix控制台确认数据是否插入成功:
iex -S mix # 在控制台内执行查询 App.Repo.all(App.Items.Item)
- 执行种子数据命令:
内容的提问来源于stack exchange,提问作者William
相关产品推荐
相关产品推荐

