Description
This may already be solved, as I'm running on version 0.4.0-beta.1
.
Issue
I run cargo sqlx prepare -- --bin <bin name>
and get a correctly specified sqlx-data.json
file. However, if I run it again, I now get the "empty" file, only specifying what db I'm using:
{
"db": "PostgreSQL"
}
And along with this, I get warning: no queries found; do you have the `offline` feature enabled
, which seems off, since I do have "offline" enabled.
Indeed the same issue arises if I run cargo sqlx prepare --check -- --bin <bin name>
Workaround
If I run cargo clean
before the commands, everything works fine. This is both in terms of rerunning the builder, and running --check
.
What Else I've Tried
- From Delete target/sqlx before invoking cargo in
cargo sqlx prepare
#722, I tried just manually deleting./target/sqlx
instead of fullcargo clean
but that didn't work - the folder is empty anyway. - I tried just deleting
target/CACHEDIR.TAG
, didn't work; same fortarget/.rustc_info.json
- I trashed just
./target/debug
and that worked... But this is rather similar to runningcargo clean
I guess - On quick search, didn't find a matching issue here or on Discord
Version
My sqlx
setup:
[dependencies.sqlx]
version = "0.4.0-beta.1"
default-features = false
features = [ "runtime-tokio", "macros", "postgres", "uuid", "chrono", "migrate", "offline" ]
Postgres: postgres (PostgreSQL) 13.0 (Debian 13.0-1.pgdg100+1)
running on postgres Docker (image 817f2d3d51ec)
Thanks
For the great crate!
Activity
Nehliin commentedon Nov 14, 2020
I ran into the same issue on version
0.4.1
but my problem isn't fixed by runningcargo clean
or removing the target folderhollg commentedon Nov 14, 2020
I have the same issue, also on
0.4.0-beta.1
. I'm not entirely sure whether this is related, but I also get the messageWhen I run
cargo sqlx prepare --check -- --bin --<bin_name>
immediately aftercargo sqlx prepare -- --bin --<bin_name>
.colmanhumphrey commentedon Nov 18, 2020
Ah @Nehliin do you mean it works the first time for you, then refuses to work? Or you only ever get an empty
sqlx-data.json
file?Also, quick update on my end: the issue persists with sqlx
0.4.1
, and withsqlx-cli 0.2.0
. Possible it's something on my end!Nehliin commentedon Nov 21, 2020
@colmanhumphrey It generates an almost empty
sqlx-data.json
(only contains top level databasename) but rerunning it with the empty json solved it for me.TatriX commentedon Feb 4, 2021
In my case
cargo
can't see changes made to sql files (I usesqx::query_files_as!
). I think this is the reason whycargo sqlx prepare
generates empty file for me. In order to fix both cargo recompiling binary with proper sql files and generating non-empty json I need totouch src/lib.rs
to make cargo see that it needs to recompile.jplatte commentedon Feb 4, 2021
The
query_file_as!
issue is being tracked at #663. The fix should actually be relatively simple.spigaz commentedon Apr 18, 2021
The cargo clean workaround is still needed in version cargo-sqlx 0.5.1.
abonander commentedon Apr 28, 2021
Closing as duplicate of #663
oessaid commentedon Oct 1, 2021
@abonander: Please note that this issue is indeed a duplicate of #663 for the specialized case of
query_as_file!
, but more generally speaking a workaround is still necessary for the standardquery!
case as of0.5.7
.Using
cargo clean
(as in the original comment) works but is obviously time-consuming.My own workaround is to prefix both
cargo sqlx prepare -- --bin <...>
andcargo sqlx prepare --check -- --bin <...>
withtouch src/lib.rs
. I haven't seen it mentioned above and it has been working for me so far.The exact commands I use are:
For context, I have this in my
Cargo.toml
:Are there any plans to improve this experience or mention this as a caveat in the docs? Is there anything I could do that would be helpful?
Thanks (for looking into this but also for the awesome crate).
matschaffer-roblox commentedon Nov 11, 2022
I ran into this today and I think it might have been caused by a mismatch between sqlx-cli (0.6.0) and sqlx (0.6.2). Re-running
cargo install sqlx-cli
seemed to get things working again.DanielJoyce commentedon Nov 22, 2022
Yes. Updating cli fixed it for me.
morukele commentedon Jan 9, 2023
I had the same issue and updating the CLI fixed it for me.
s0lst1ce commentedon Jan 28, 2023
Same but only for a while. After doing it for a few crates in a workspace, it started failing again.
7 remaining items