{"id":1216,"hash":"0a8732655ffe939cd32b0ca8a48745d4000d4077f70b70cbb2d5c745b8ae0de0","pattern":"Rust Diesel not building with error use of undeclared crate or module","full_message":"I am trying to create my first Rust app with database support, I am using Diesel with SQLite, whenever I build my application I get the following error message:\n\nfailed to resolve: use of undeclared crate or module `categorys`\n  --> src/models.rs:14:12\n   |\n14 | pub struct Category {\n   |            ^^^^^^^^ use of undeclared crate or module `categorys`\n\nerror[E0433]: failed to resolve: use of undeclared crate or module `correspondents`\n  --> src/models.rs:21:12\n   |\n21 | pub struct Correspondent {\n   |            ^^^^^^^^^^^^^ use of undeclared crate or module `correspondents`\n\nerror[E0433]: failed to resolve: use of undeclared crate or module `doctypes`\n  --> src/models.rs:27:12\n   |\n27 | pub struct Doctype {\n   |            ^^^^^^^ use of undeclared crate or module `doctypes`\n\nerror[E0433]: failed to resolve: use of undeclared crate or module `documents`\n  --> src/models.rs:37:12\n   |\n37 | pub struct Document {\n   |            ^^^^^^^^ use of undeclared crate or module `documents`\n\nerror: aborting due to 4 previous errors\n\nMy cargo.toml:\n\n[package]\nname = \"Rekorder\"\nversion = \"0.1.0\"\nauthors = [\"ossama\"]\nedition = \"2018\"\n\n# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html\n\n[dependencies]\ndiesel = { version = \"1.4.4\", features = [\"sqlite\"] }\ndiesel_cli_ext = \"0.3.6\"\ndotenv = \"0.15.0\"\nchrono = \"0.4\"\n\n[dependencies.gtk]\nversion = \"0.9.0\"\nfeatures = [\"v3_16\"]\n\n[dependencies.gio]\nversion = \"\"\nfeatures = [\"v2_44\"]\n\nMy models.rs:\n\n// Generated by diesel_ext\n\n#![allow(unused)]\n#![allow(clippy::all)]\n\nuse chrono::NaiveDate;\nuse diesel::Queryable;\nuse diesel::Identifiable;\nuse diesel::sql_types::Binary;\n\n#[derive(Queryable, Debug, Identifiable)]\npub struct Category {\n    pub id: i32,\n    pub name: String,\n    pub color: Option<i32>,\n}\n\n#[derive(Queryable, Debug, Identifiable)]\npub struct Correspondent {\n    pub id: i32,\n    pub name: String,\n}\n\n#[derive(Queryable, Debug, Identifiable)]\npub struct Doctype {\n    pub id: i32,\n    pub name: String,\n    pub correspondent_name: Option<String>,\n    pub support_extra_date_number: Option<bool>,\n    pub icon: Option<Binary>,\n}\n\n#[derive(Queryable, Debug, Identifiable)]\n#[primary_key(number, date_of_document, doc_type_id)]\npub struct Document {\n    pub number: i32,\n    pub date_of_document: NaiveDate,\n    pub doc_type_id: i32,\n    pub extra_number: Option<String>,\n    pub extra_date: Option<NaiveDate>,\n    pub correspondent_id: i32,\n    pub content: String,\n    pub notes: Option<String>,\n    pub category_id: Option<i32>,\n    pub document_file_name: Option<String>,\n    pub document_file_size: Option<i32>,\n    pub document_file: Option<Binary>,\n}\n\nMy schema.rs:\n\ntable! {\n    category (id) {\n        id -> Integer,\n        name -> Text,\n        color -> Nullable<Integer>,\n    }\n}\n\ntable! {\n    correspondent (id) {\n        id -> Integer,\n        name -> Text,\n    }\n}\n\ntable! {\n    doctype (id) {\n        id -> Integer,\n        name -> Text,\n        correspondent_name -> Nullable<Text>,\n        support_extra_date_number -> Nullable<Bool>,\n        icon -> Nullable<Binary>,\n    }\n}\n\ntable! {\n    document (number, date_of_document, doc_type_id) {\n        number -> Integer,\n        date_of_document -> Date,\n        doc_type_id -> Integer,\n        extra_number -> Nullable<Text>,\n        extra_date -> Nullable<Date>,\n        correspondent_id -> Integer,\n        content -> Text,\n        notes -> Nullable<Text>,\n        category_id -> Nullable<Integer>,\n        document_file_name -> Nullable<Text>,\n        document_file_size -> Nullable<Integer>,\n        document_file -> Nullable<Binary>,\n    }\n}\n\njoinable!(document -> category (category_id));\njoinable!(document -> correspondent (correspondent_id));\njoinable!(document -> doctype (doc_type_id));\n\nallow_tables_to_appear_in_same_query!(\n    category,\n    correspondent,\n    doctype,\n    document,\n);\n\nand finally my main.rs:\n\nmod models;\nfn main() {\n\n    println!(\"Hello, world!\");\n}\n\nI tried to add use schema::* to my model.rs to no success as the model is not found.\nI also tried this solution to no success.\n\nI cannot get to use the correct scopes, I am new to rust, I still getting used to its paradigm","ecosystem":"cargo","package_name":"sqlite","package_version":null,"solution":"Diesel assumes that your table name is the plural, snake-case form of your struct name. Because your table name does not follow this convention you can specify the table name explicitly:\n\n#[derive(Queryable, Identifiable)]\n#[table_name = \"category\"]\npub struct Category {\n    // ...\n}\n\n#[derive(Queryable, Identifiable)]\n#[table_name = \"correspondent\"]\npub struct Correspondent {\n    // ...\n}\n\n// and do the same to the rest of your models...","confidence":0.8,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/66398071/rust-diesel-not-building-with-error-use-of-undeclared-crate-or-module","votes":9,"created_at":"2026-04-19T04:52:37.215355+00:00","updated_at":"2026-04-19T04:52:37.215355+00:00"}