Ecto 无法在项目中找到回购协议
Ecto Cannot Find Repo In Project
我正在尝试将 Ecto 添加到我的项目中。这是一个标准项目,不是用 --s
生成的来添加主管。
到目前为止我用过[=19=]
mix ecto.gen.repo -r MyApp.Repo
生成它就好了。
在我的 config/dev.exs
中,我有以下内容:
config :my_app,
ecto_repos: [MyApp.Repo]
config :my_app, MyApp.Repo,
adapter: Ecto.Adapters.Postgres,
database: System.get_env("DATABASE_NAME"),
username: System.get_env("DATABASE_USER"),
password: System.get_env("DATABASE_PASSWORD"),
hostname: System.get_env("DATABASE_HOST"),
port: System.get_env("DATABASE_PORT")
在 myapp/repo.ex
我有:
defmodule MyApp.Repo do
use Ecto.Repo, otp_app: :my_app
end
但是,当我使用
创建存储库时
mix ecto.create --env=dev
我明白了
warning: could not find Ecto repos in any of the apps: [:my_app].
You can avoid this warning by passing the -r flag or by setting the
repositories managed by those applications in your config/config.exs:
config :eos, ecto_repos: [...]
如果我省略 --env
标志,也会发生这种情况。
我绝望地迷路了。这与入门指南一致(减去了它没有指出需要的主管内容),我在这里停滞不前。谁能帮我解决这个问题?谢谢!
Elixir 默认只加载 config/config.exs
中的配置声明。许多项目(包括 Phoenix)使用的 <env>.exs
约定要求将以下行添加到 config/config.exs
的末尾以加载正确的 exs 文件:
import_config "#{Mix.env}.exs"
我正在尝试将 Ecto 添加到我的项目中。这是一个标准项目,不是用 --s
生成的来添加主管。
到目前为止我用过[=19=]
mix ecto.gen.repo -r MyApp.Repo
生成它就好了。
在我的 config/dev.exs
中,我有以下内容:
config :my_app,
ecto_repos: [MyApp.Repo]
config :my_app, MyApp.Repo,
adapter: Ecto.Adapters.Postgres,
database: System.get_env("DATABASE_NAME"),
username: System.get_env("DATABASE_USER"),
password: System.get_env("DATABASE_PASSWORD"),
hostname: System.get_env("DATABASE_HOST"),
port: System.get_env("DATABASE_PORT")
在 myapp/repo.ex
我有:
defmodule MyApp.Repo do
use Ecto.Repo, otp_app: :my_app
end
但是,当我使用
创建存储库时mix ecto.create --env=dev
我明白了
warning: could not find Ecto repos in any of the apps: [:my_app].
You can avoid this warning by passing the -r flag or by setting the
repositories managed by those applications in your config/config.exs:
config :eos, ecto_repos: [...]
如果我省略 --env
标志,也会发生这种情况。
我绝望地迷路了。这与入门指南一致(减去了它没有指出需要的主管内容),我在这里停滞不前。谁能帮我解决这个问题?谢谢!
Elixir 默认只加载 config/config.exs
中的配置声明。许多项目(包括 Phoenix)使用的 <env>.exs
约定要求将以下行添加到 config/config.exs
的末尾以加载正确的 exs 文件:
import_config "#{Mix.env}.exs"