{"id":1193,"hash":"946c9f2835fc0f7e52e8f37a6f47107bd2d9950adade7cb4c3ef1b8fa783e2c6","pattern":"Cannot use UUID as a primary key: Uuid: diesel::Expression is not satisfied","full_message":"I want to have a UUID field as the primary field in a Postgres table, but I get the following error:\n\nerror[E0277]: the trait bound `uuid::Uuid: diesel::Expression` is not satisfied\n --> database/src/models.rs:3:35\n  |\n3 | #[derive(Debug, Clone, Queryable, Insertable)]\n  |                                   ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `uuid::Uuid`\n  |\n  = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Uuid>` for `uuid::Uuid`\n\nSome older questions are there about UUID with diesel but none of them are insertable and I am getting the error specifically in that. I am using diesel with actix web. \n\nHere is my model:\n\nuse crate::schema::users;\n\n#[derive(Debug, Clone, Queryable, Insertable)]\n#[table_name=\"users\"]\npub struct User {\n    pub id: uuid::Uuid,\n    pub phone: String,\n    pub name: String,\n    pub password: String,\n}\n\nAnd my table schema\n\ntable! {\n    users (id) {\n        id -> Uuid,\n        name -> Text,\n        phone -> Text,\n        password -> Text,\n    }\n}\n\nI found some old post that suggested that the field might be nullable but id is the PRIMARY KEY in my table up.sql, so it is not nullable.\n\nThe table is generated from diesel-cli, do there doesn't seem to be any problem there.\n\nHere is my Cargo.toml\n\ndiesel = { version = \"1.0.0\", features = [\"postgres\", \"r2d2\", \"uuid\"] }\nuuid = { version = \"0.8\", features = [\"v4\"] }\nserde = { version = \"1.0\", features = [\"derive\"] }\nserde_json = \"1.0\"","ecosystem":"cargo","package_name":"postgresql","package_version":null,"solution":"It's always good to see what's in your Cargo.lock file and look are pointing for package dependencies.\n\n[[package]]\nname = \"diesel\"\nversion = \"1.4.4\"\n...\n \"uuid 0.6.5\", <-- It was older version even I've installed newest version of uuid\n]\n\nas soon as change features to uuidv07 and run cargo update Cargo.lock file also changes. If you want to check which Uuid is applied by diesel. It's possible checking it by looking to the source of the diesel::sql_types::Uuid to be sure they are using the same versions as uuid::Uuid.\n\nP.S: Answer was commented by @weiznich in the question post, just adding little bit detailed information and as an answer post whom, who not read comments and look for answer only","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/60441600/cannot-use-uuid-as-a-primary-key-uuid-dieselexpression-is-not-satisfied","votes":8,"created_at":"2026-04-19T04:52:34.054619+00:00","updated_at":"2026-04-19T04:52:37.216678+00:00"}