sfackler / rust-postgres

Native PostgreSQL driver for the Rust programming language
Apache License 2.0
3.43k stars 436 forks source link

Odd WrongType error with custom type #1175

Closed y0zong closed 2 weeks ago

y0zong commented 2 weeks ago

I followed postgres_types step by step but still get an error

Error { kind: ToSql(2), cause: Some(WrongType { postgres: Other(Other { name: "song_type", oid: 329630, kind: Enum(["original", "cover"]), schema: "public" }), rust: "miusic::song::SongType" }) }

sql

CREATE TYPE song_type AS ENUM(
        'original',
        'cover'
);

rust enum

#[derive(Debug, Deserialize, ToSql)]
#[postgres(name = "song_type", rename_all = "snake_case")]
pub enum SongType {
    Original,
    Cover,
}

because I use SongType from post which is from a formdata so I keep Deserialize derive, and I don't need deserialize from Row so I removed FromSql(actually when I keep it and remove Deserialize the error is same). Other than this there is no difference from the demo code, what I miss?