柴油迁移力字符串而不是schema.rs中的uuid
我对柴油迁移有问题。我需要将UUID作为模型的主要密钥实现。我在UUID集成方面有很多问题(功能UUIDV07,UUID板条箱,..)我的模型中的一种字段。
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>,
}
}
使用varchar而不是uuid是正常的吗?
uuid = { version = "0.8.2", features = ["serde", "v4"] }
diesel = { version = "1.4.5", features = ["postgres", "r2d2", "uuidv07"] }
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
柴油不会将任何东西迫使您。它只是从数据库系统中读取类型。因此,如果它输出
varchar
作为特定列的类型,则表示您的数据库系统记录varchar
(出于何种原因)作为此列的类型。或对此有所不同:这里的问题不是柴油,而是您的迁移,现有数据库架构和数据库之间的交互。作为您的问题架构或有关数据库系统的有关问题的一部分,我均未提供有关您的数据库系统的信息,因此我在这里没有太多的信息可以将您指向正确的方向。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 recordedVarchar
(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.