-1

I have a problem with the diesel migration. I need to implement Uuid as primary key for a model. I got a lot of issues with the Uuid integration (feature uuidv07, uuid crate,..) but when I specify the type uuid in the migration, diesel generate a "Varchar" field in the migration, so I can't use Uuid as a type of field in my model.

users.sql

CREATE TABLE users (
  id UUID PRIMARY KEY,
  email VARCHAR NOT NULL,
  name VARCHAR NOT NULL,
  password VARCHAR NOT NULL,
  id_role INT,
  CONSTRAINT fk_role
    FOREIGN KEY(id_role)
      REFERENCES roles(id)
)

schema.rs


table! {
    users (id) {
        id -> Varchar,
        email -> Varchar,
        name -> Varchar,
        password -> Varchar,
        id_role -> Nullable<Int4>,
    }
}

Is this normal to use Varchar and not Uuid ?

uuid = { version = "0.8.2", features = ["serde", "v4"] }
diesel = { version = "1.4.5", features = ["postgres", "r2d2", "uuidv07"] }

Thanks.

jenoh
  • 165
  • 3
  • 17

1 Answers1

1

Diesel does not force anything onto you. It just reads the types from your database system. So if it outputs a Varchar as type for a specific column that means your database system recorded Varchar (for whatever reason) as type for this column. Or to word it differently: The problem here is not diesel, but likely an interaction between your migration, your existing database schema and your database. As neither information about your pre-existing database schema nor about your database system is provided as part of your question there is not much I can add here to point you into the right direction.

weiznich
  • 2,910
  • 9
  • 16