I followed the getting started tutorial and that worked okay.
But now I'm seeing these errors when I run cargo check on another project I'm trying to use diesel on.
table! in this scopeQueryable in this scopeThe first in particular is in a file generated by diesel.
Implementing the same functionality as the "getting started" tutorial, pretty much.
That it should compile (or show me some other errors).
$ cargo check --verbose
Fresh unicode-xid v0.1.0
Fresh cc v1.0.18
Fresh libc v0.2.42
Fresh void v1.0.2
Fresh cfg-if v0.1.4
Fresh ucd-util v0.1.1
Fresh rustc-demangle v0.1.9
Fresh lazy_static v1.0.2
Fresh utf8-ranges v1.0.0
Fresh byteorder v1.2.4
Fresh bitflags v1.0.3
Fresh matches v0.1.7
Fresh proc-macro2 v0.4.9
Fresh proc-macro2 v0.3.8
Fresh memchr v2.0.1
Fresh time v0.1.40
Fresh rand v0.4.2
Fresh unreachable v1.0.0
Fresh regex-syntax v0.6.2
Fresh quote v0.6.4
Fresh quote v0.5.2
Fresh aho-corasick v0.6.6
Fresh num-traits v0.2.5
Fresh thread_local v0.3.5
Fresh serde v1.0.70
Fresh pq-sys v0.4.6
Fresh syn v0.14.7
Fresh syn v0.13.11
Fresh backtrace-sys v0.1.23
Fresh num-integer v0.1.39
Fresh regex v1.0.2
Fresh uuid v0.6.5
Fresh synstructure v0.9.0
Fresh serde_derive v1.0.70
Fresh diesel_derives v1.3.0
Fresh backtrace v0.3.9
Fresh chrono v0.4.5
Fresh failure_derive v0.1.2
Fresh diesel v1.3.2
Fresh failure v0.1.2
Fresh dotenv v0.13.0
Checking dp v0.1.0 (file:///home/me/work/home/rust/dp/dp)
Runningrustc --crate-name dp src/lib.rs --crate-type lib --emit=dep-info,metadata -C debuginfo=2 -C metadata=b98d1f9a214d87e3 -C extra-filename=-b98d1f9a214d87e3 --out-dir /home/me/work/home/rust/dp/dp/target/debug/deps -C incremental=/home/me/work/home/rust/dp/dp/target/debug/incremental -L dependency=/home/me/work/home/rust/dp/dp/target/debug/deps --extern serde_derive=/home/me/work/home/rust/dp/dp/target/debug/deps/libserde_derive-0da1fdb6e3476cb6.so --extern uuid=/home/me/work/home/rust/dp/dp/target/debug/deps/libuuid-d10e8fac523e9907.rmeta --extern chrono=/home/me/work/home/rust/dp/dp/target/debug/deps/libchrono-64c508931f79b192.rmeta --extern serde=/home/me/work/home/rust/dp/dp/target/debug/deps/libserde-082b5e8e59eeb2b9.rmeta --extern diesel=/home/me/work/home/rust/dp/dp/target/debug/deps/libdiesel-3a4cd3de6c40644c.rmeta --extern dotenv=/home/me/work/home/rust/dp/dp/target/debug/deps/libdotenv-d099a357f49696b9.rmeta --extern matches=/home/me/work/home/rust/dp/dp/target/debug/deps/libmatches-368d41e99865b973.rmeta -L native=/usr/lib/x86_64-linux-gnu -L native=/home/me/work/home/rust/dp/dp/target/debug/build/backtrace-sys-6dfb52fe4b98ef15/out
error: cannot find macrotable!in this scope
--> src/schema.rs:1:1
|
1 | table! {
| ^^^^^error: cannot find derive macro
Queryablein this scope
--> src/models.rs:1:10
|
1 | #[derive(Queryable)]
| ^^^^^^^^^error: aborting due to 2 previous errors
error: Could not compile
dp.Caused by:
process didn't exit successfully:rustc --crate-name dp src/lib.rs --crate-type lib --emit=dep-info,metadata -C debuginfo=2 -C metadata=b98d1f9a214d87e3 -C extra-filename=-b98d1f9a214d87e3 --out-dir /home/me/work/home/rust/dp/dp/target/debug/deps -C incremental=/home/me/work/home/rust/dp/dp/target/debug/incremental -L dependency=/home/me/work/home/rust/dp/dp/target/debug/deps --extern serde_derive=/home/me/work/home/rust/dp/dp/target/debug/deps/libserde_derive-0da1fdb6e3476cb6.so --extern uuid=/home/me/work/home/rust/dp/dp/target/debug/deps/libuuid-d10e8fac523e9907.rmeta --extern chrono=/home/me/work/home/rust/dp/dp/target/debug/deps/libchrono-64c508931f79b192.rmeta --extern serde=/home/me/work/home/rust/dp/dp/target/debug/deps/libserde-082b5e8e59eeb2b9.rmeta --extern diesel=/home/me/work/home/rust/dp/dp/target/debug/deps/libdiesel-3a4cd3de6c40644c.rmeta --extern dotenv=/home/me/work/home/rust/dp/dp/target/debug/deps/libdotenv-d099a357f49696b9.rmeta --extern matches=/home/me/work/home/rust/dp/dp/target/debug/deps/libmatches-368d41e99865b973.rmeta -L native=/usr/lib/x86_64-linux-gnu -L native=/home/me/work/home/rust/dp/dp/target/debug/build/backtrace-sys-6dfb52fe4b98ef15/out(exit code: 101)
No.
Running cargo check on my codebase.
I have the following lines in my src/lib.rs file in this order:
extern crate diesel;
// ...
use diesel::prelude::*;
// ...
mod schema;
mod models;
The diesel-generated src/schema.rs file looks like this:
table! {
users (id) {
id -> Int4,
email -> Varchar,
given_name -> Varchar,
family_name -> Varchar,
crypted_password -> Varchar,
admin -> Bool,
deleted -> Bool,
}
}
And the src/models.rs file looks like this:
#[derive(Queryable)]
pub struct User {
pub id: i32,
pub email: String,
pub given_name: String,
pub family_name: String,
pub crypted_password: String,
pub admin: bool,
pub deleted: bool,
}
error: cannot find macro table! in this scope
error: cannot find derive macro Queryable in this scope
This sounds like that the #[macro_use] annotation is missing on your extern crate diesel; import.
(I closed this issue because there is nothing actionable for the diesel team here. Feel free to response here or use our gitter channel to ask future questions.)
Oh good grief. Yes, it was precisely that -- thank you!
weiznich's answer to biot023's question helped me!
use our gitter channel to ask future questions.)
Just wanted to point out that I would never have found this solution in the gitter channel, but it did help me here!
So it seems counterproductive to keep answering the same questions over and over on the gitter channel when you could just answer them once and make them googleable
@zwhitchcox Gitter chat results are also indexed by google and show up in the search results if they are relevant. Also it is not useful to comment twice here with basically the same massage.
@zwhitchcox Gitter chat results are also indexed by google and show up in the search results if they are relevant. Also it is not useful to comment twice here with basically the same massage.
I did not realize that...also I did not comment twice with basically the same message. I would've just added it, but github marks your post as edited, and then people don't know what you edited. So, I could've just deleted the post and reposted it with the added information, but then it sends people multiple notifications, so it seemed preferable to just make another comment.
Could someone update the tutorial to include the #[macro_use] annotation on the website? The code has it correct, but I assume many people are follwing the guide at https://diesel.rs/guides/getting-started/
@christian-oudard I'm not sure what you are revering to. Literally the first example showing rust code in the getting started guide already includes the necessary #[macro_use] annotation.
src/bin/show_posts.rs is missing it, just a minor detail.
@christian-oudard We are happy to receive a PR for this, though technically speaking #[macro_use] is not necessary to make exactly this example working.
Most helpful comment
This sounds like that the
#[macro_use]annotation is missing on yourextern crate diesel;import.(I closed this issue because there is nothing actionable for the diesel team here. Feel free to response here or use our gitter channel to ask future questions.)