Phoenix框架执行mix ecto.create创建数据库失败求助
mix ecto.create CaseClauseError with Postgrex & PostgreSQL 11.7 Hey there, let's work through this frustrating issue you're hitting. The core problem here is a compatibility mismatch between your older Postgrex version (0.12.2) and PostgreSQL 11.7—Postgrex 0.12.x doesn't properly handle version parsing for PostgreSQL 11+, which is exactly what's triggering that hidden CaseClauseError in Postgrex.Utils.parse_version/1.
Here's how to resolve this step by step:
1. Upgrade Postgrex to a Compatible Version
Your current Postgrex version is too old to support PostgreSQL 11. You'll need to update it to at least version 0.14.0 (which adds full support for PostgreSQL 11).
- Open your project's
mix.exsfile, find the postgrex dependency line, and update it to:{:postgrex, ">= 0.14.0"} - Run these commands to fetch and compile the updated dependency:
mix deps.get mix deps.compile
2. Ensure Ecto & Ecto.SQL Compatibility
If your Ecto version is also outdated, it might conflict with the newer Postgrex. Check your mix.exs for the ecto_sql dependency and update it to a version compatible with Postgrex 0.14+:
{:ecto_sql, ">= 3.0.0"}
Again, run mix deps.get to pull in the updated package.
3. Double-Check Database Connection Configuration
Even though you confirmed credentials work in PgAdmin, let's rule out any subtle config issues:
- In
config/dev.exs, verify yourHelloPhoenix.Repoconfig includes all correct details:config :hello_phoenix, HelloPhoenix.Repo, username: "postgres", password: "postgres", database: "hello_phoenix_dev", hostname: "localhost", port: 5432, pool_size: 10 - Confirm PostgreSQL's
pg_hba.conffile (located at/etc/postgresql/11/main/pg_hba.confon Ubuntu) allows local connections with password authentication. Look for lines like:
If you make changes here, restart PostgreSQL with:local all postgres md5 host all all 127.0.0.1/32 md5sudo systemctl restart postgresql@11-main
4. Verify Direct Database Connection
Test that you can connect to PostgreSQL via the command line to eliminate server-side issues:
psql -U postgres -d postgres
If you can log in successfully, the database server is working correctly, and the fix should come from updating your Elixir dependencies.
After completing these steps, try running mix ecto.create again—it should work without the CaseClauseError.
内容的提问来源于stack exchange,提问作者Max Wen

