我正在Windows 10中安装phoenix框架,并且已经创建了一个应用程序“项目”。键入mix ecto.create和phx.server混合时出现错误。有人可以帮我解决这个问题吗?谢谢。
mix ecto.create中发生错误
[error] GenServer #PID<0.318.0> terminating ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused (db_connection) lib/db_connection/connection.ex:163: DBConnection.Connection.connect/2 (connection) lib/connection.ex:622: Connection.enter_connect/5 (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3 Last message: nil State: Postgrex.Protocol** (Mix) The database for Project.Repo couldn't be created: an exception was raised:/* (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused( db_connection) lib/db_connection/connection.ex:163: DBConnection.Connection.connect/2 (connection) lib/connection.ex:622: Connection.enter_connect/5 (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
混合phx.server中发生错误
** (UndefinedFunctionError) function Plug.Cowboy.child_spec/1 is undefined (module Plug.Cowboy is not available)
Plug.Cowboy.child_spec([scheme: :http, plug: {ProjectWeb.Endpoint, []}, options: [dispatch: [_: [{"/phoenix/live_reload/socket/websocket", Phoenix.Endpoint.CowboyWebSocket, {Phoenix.Transports.WebSocket, {ProjectWeb.Endpoint, Phoenix.LiveReloader.Socket, [path: "/websocket", serializer: [{Phoenix.Socket.V1.JSONSerializer, "~> 1.0.0"}, {Phoenix.Socket.V2.JSONSerializer, "~> 2.0.0"}], timeout: 60000, transport_log: false, compress: false]}}}, {"/socket/websocket", Phoenix.Endpoint.CowboyWebSocket, {Phoenix.Transports.WebSocket, {ProjectWeb.Endpoint, ProjectWeb.UserSocket, [path: "/websocket", serializer: [{Phoenix.Socket.V1.JSONSerializer, "~> 1.0.0"}, {Phoenix.Socket.V2.JSONSerializer, "~> 2.0.0"}], timeout: 60000, transport_log: false, compress: false]}}}, {:_, Plug.Adapters.Cowboy.Handler, {ProjectWeb.Endpoint, []}}]], port: 4000, otp_app: :project]])
(phoenix) lib/phoenix/endpoint/cowboy_adapter.ex:96: Phoenix.Endpoint.CowboyAdapter.child_spec/3
(phoenix) lib/phoenix/endpoint/supervisor.ex:111: anonymous fn/6 in Phoenix.Endpoint.Supervisor.server_children/4
(elixir) lib/enum.ex:1940: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix) lib/phoenix/endpoint/supervisor.ex:102: Phoenix.Endpoint.Supervisor.server_children/4
(phoenix) lib/phoenix/endpoint/supervisor.ex:67: Phoenix.Endpoint.Supervisor.init/1
(stdlib) supervisor.erl:295: :supervisor.init/1
(stdlib) gen_server.erl:374: :gen_server.init_it/2
(stdlib) gen_server.erl:342: :gen_server.init_it/6
(stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
** (Mix) Could not start application project: Project.Application.start(:normal, []) returned an error: shutdown: failed to start child: ProjectWeb.Endpoint
** (EXIT) an exception was raised:
** (UndefinedFunctionError) function Plug.Cowboy.child_spec/1 is undefined (module Plug.Cowboy is not available)
Plug.Cowboy.child_spec([scheme: :http, plug: {ProjectWeb.Endpoint, []}, options: [dispatch: [_: [{"/phoenix/live_reload/socket/websocket", Phoenix.Endpoint.CowboyWebSocket, {Phoenix.Transports.WebSocket, {ProjectWeb.Endpoint, Phoenix.LiveReloader.Socket, [path: "/websocket", serializer: [{Phoenix.Socket.V1.JSONSerializer, "~> 1.0.0"}, {Phoenix.Socket.V2.JSONSerializer, "~> 2.0.0"}], timeout: 60000, transport_log: false, compress: false]}}}, {"/socket/websocket", Phoenix.Endpoint.CowboyWebSocket, {Phoenix.Transports.WebSocket, {ProjectWeb.Endpoint, ProjectWeb.UserSocket, [path: "/websocket", serializer: [{Phoenix.Socket.V1.JSONSerializer, "~> 1.0.0"}, {Phoenix.Socket.V2.JSONSerializer, "~> 2.0.0"}], timeout: 60000, transport_log: false, compress: false]}}}, {:_, Plug.Adapters.Cowboy.Handler, {ProjectWeb.Endpoint, []}}]], port: 4000, otp_app: :project]])
(phoenix) lib/phoenix/endpoint/cowboy_adapter.ex:96: Phoenix.Endpoint.CowboyAdapter.child_spec/3
(phoenix) lib/phoenix/endpoint/supervisor.ex:111: anonymous fn/6 in Phoenix.Endpoint.Supervisor.server_children/4
(elixir) lib/enum.ex:1940: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix) lib/phoenix/endpoint/supervisor.ex:102: Phoenix.Endpoint.Supervisor.server_children/4
(phoenix) lib/phoenix/endpoint/supervisor.ex:67: Phoenix.Endpoint.Supervisor.init/1
(stdlib) supervisor.erl:295: :supervisor.init/1
(stdlib) gen_server.erl:374: :gen_server.init_it/2
(stdlib) gen_server.erl:342: :gen_server.init_it/6
(stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
我希望浏览器中输出Phoenix框架欢迎页面。
答案 0 :(得分:1)
第一则消息表明您的应用程序无法连接到数据库。我假设(基于端口)您正在使用PostgreSQL。在这种情况下,您需要确保已在计算机上安装并运行PostgreSQL服务器(您可以在此处找到安装说明:https://www.postgresql.org/download/)
关于第二条消息,Phoenix Github问题中提到了此问题,您可以在这里找到它:https://github.com/phoenixframework/phoenix/issues/3113。那里提到的解决方案包括:
1.更新Phoenix版本(该错误应在v1.4.0中解决,请检查您的mix.exs
文件中的版本)
2.将:plug_cowboy, "~> 2.0"
添加到依赖项列表中(确保在此之后运行mix deps.get
)