Cargo sqlx prepare

I'm trying to use the query! macro family in sqlx. This gives errors starting with

error: set `DATABASE_URL` to use query macros online, or run `cargo sqlx prepare` to update the query cache

Yes, sqlx-cli is installed. If I follow the suggestion and run cargo sqlx prepare, I get an error with the same line at the top. In summary, the error message implies that you need to run cargo sqlx prepare before you can run cargo sqlx prepare.

It does manage to create an empty .sqlx directory.

The behaviour is the same with sqlx-cli versions 0.7.4 and 0.8.2.

Any ideas?

1 Like

Hmm, if I'm interpreting the docs correctly, you need to have DATABASE_URL set (or have a .env file) while running cargo sqlx prepare in order to generate the .sqlx directory, and then in order to use the cache in .sqlx you have to unset DATABASE_URL.

In which case I'm underwhelmed by the quality of the error message.