sfackler / rust-postgres

Native PostgreSQL driver for the Rust programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Odd WrongType error with custom type

y0zong opened this issue · comments

commented

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?