quinta-feira, 1 de maio de 2025

Solution to sqlx prepare error: failed to lookup address information: Name or service not known

I was getting the error "failed to lookup address information: Name or service not known" when running the command cargo sqlx prepare. The error seemed obvious — my DATABASE_URL environment variable was probably incorrect. However, after checking everything and confirming that it was correct (ad-hoc connections were working, and even the service startup connected successfully), I figured out the issue:

My service required additional environment variables to start. Without these env vars, it wouldn't start and would return an error. It turns out that when running cargo sqlx prepare without those variables, the error gets silently swallowed, and the database connection simply fails.

After supplying the same environment variables I use for cargo run to cargo sqlx prepare, the problem was resolved.

Nenhum comentário:

Postar um comentário