How to fix "cannot find derive macro `FromRow` in this scope"?

I try to create a connection with a PostgreSQL databse using the Rocket framework.

This is my cargo.tml:

name = "TestRust"
version = "0.1.0"
edition = "2021"

rand = "0.8.3"
rocket = { version = "=0.5.0-rc.3", features = ["secrets"] }
serde = { version = "1", features = ["derive"] }

version = "=0.1.0-rc.3"
features = ["handlebars", "tera"]

version = "=0.1.0-rc.3"
features = ["sqlx_postgres"]


and this is my

#[macro_use] extern crate rocket;

use rocket::fs::{FileServer, relative};
use rocket::futures::{FutureExt, TryFutureExt};
use serde::{Deserialize, Serialize};
use rocket_db_pools::{Connection, Database};
use rocket_dyn_templates::{Template, context};
use rocket_db_pools::sqlx::{self, Row};
use sqlx::FromRow;

struct Logs(sqlx::PgPool);

#[derive(Deserialize, Serialize, FromRow)]
#[serde(crate = "rocket::serde")]
pub struct Produit {
    //#[serde(skip_deserializing, skip_serializing_if = "Option::is_none")]
    id: Option<i64>,
    name: String,
    fk_categorie: String,

and this is the error code when i build:

error: cannot find derive macro `FromRow` in this scope
  --> src\
14 | #[derive(Deserialize, Serialize, FromRow)]
   |                                  ^^^^^^^
note: `FromRow` is imported here, but it is only a trait, without a derive macro
  --> src\
9  | use sqlx::FromRow;
   |     ^^^^^^^^^^^^^

I tried to change the version of serde but I got the same error. How do I fix it ?


  • There's a sqlx_macros feature for rocket_db_pools, but unfortunately it doesn't work because the macro requires the sqlx crate is present, so you need to add sqlx to Cargo.toml anyway. You can enable the macros feature on sqlx or the sqlx_macros feature on rocket_db_pools. Either will do the same thing.

    sqlx = { version = "*", default-features = false, features = ["macros"] }