賢くなりたいトイプードルの日記

データサイエンス系の話をメインにしていきます

Phoenixアプリを操作した時に起こるエラーの解決方法

Phoenixアプリを操作した時に起こるいろいろなエラーを解決する方法について記述しました。初学者なので大目に見てください。
このページにはエラーに出くわすたびに随時追加していく予定です。

(DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused

$mix ecto.create

を叩くと、

[error] GenServer #PID<0.230.0> terminating
** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
    (db_connection) lib/db_connection/connection.ex:84: 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 Phx14Db.Repo couldn't be created: killed

とエラーが出る。postgresqlをアンインストールしてインストールし直しても効果なし。

$brew postgresql-upgrade-database

でアップグレードして$mix ecto.createすると、

(Postgrex.Error) FATAL 28000 (invalid_authorization_specification) role "postgres" does not exist

[error] GenServer #PID<0.230.0> terminating
** (Postgrex.Error) FATAL 28000 (invalid_authorization_specification) role "postgres" does not exist
    (db_connection) lib/db_connection/connection.ex:84: 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 Phx14Db.Repo couldn't be dropped: killed

エラーメッセージが変わった。

$ createuser -d postgres

で postgresqlのユーザーを作ってから再度$mix ecto.createすると、

Compiling 13 files (.ex)
Generated phx14_db app
The database for Phx14Db.Repo has been created

で成功。

問題なくアプリにアクセスできるし、CRUDを記述するとインタラクティブに反映されるのだけど、以下のエラーが出る。

[error] The client's requested channel transport version "2.0.0" does not match server's version requirements of "~> 1.0"

mix.exsのdefp deps do内に

{:drab, "~> 0.10.0"}

を追記して、

$ mix deps.get

するとerrorがでなくなったけど、mix deps.get時に出たエラーが気になる。(これサーバーに異常が起きてうまく起動しなくなっただけだった。)

** (Mix) Hex dependency resolution failed, change the version

** (Mix) Hex dependency resolution failed, change the version requirements of your dependencies or unlock them (by using mix deps.update or mix deps.unlock). If you are unable to resolve the conflicts you can try overriding with {:dependency, "~> 1.0", override: true}

{:dependency, "~> 1.0", override: true} も追記すると、

** (Mix) No matching version for dependency ~> 1.0 (from: mix.exs) in registry

** (Mix) No matching version for dependency ~> 1.0 (from: mix.exs) in registry


The latest version is: 0.2.0

サーバーを立て直そうとしたら失敗したので、一旦drabとdependencyを削除して$mix deps.getしてから$mix deps.update --allしても変化なし。

[error] The client's requested channel transport version "2.0.0" does not match server's version requirements of "~> 1.0"

いろいろ調べると、この
「[error] The client's requested channel transport version "2.0.0" does not match server's version requirements of "~> 1.0" 」
phoenixjavascriptライブラリがアップデートしたのにそれにphoenixが気づいてないとかかんとかで出るエラーみたい。カレントディレクトリをPhoenixアプリにして

$npm init

するといろいろと互換性をもつよう更新してくれて、

Update available 5.6.0 → 6.5.0

Run npm i -g npm to update

と出力されたので

$sudo npm i -g npm

すると、エラーがでなくなった。