You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Phoenix框架执行mix ecto.create创建数据库失败求助

Fixing 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.exs file, 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 your HelloPhoenix.Repo config 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.conf file (located at /etc/postgresql/11/main/pg_hba.conf on Ubuntu) allows local connections with password authentication. Look for lines like:
    local   all             postgres                                md5
    host    all             all             127.0.0.1/32            md5
    
    If you make changes here, restart PostgreSQL with:
    sudo 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 22:02:43