如何在柴油模式属性中定义唯一约束

问题描述 投票:0回答:1

这是我的架构:

diesel::table! {
    account (organization_id) {
        
        #[max_length = 255]
        organization_id -> Varchar,
        
        #[max_length = 255]
        name -> Varchar,
        
        #[max_length = 255]
        description -> Varchar,
        
        account_was_verified -> Bool,
        
        #[max_length = 255]
        username -> Varchar,

        #[max_length = 255]
        password_hash -> Varchar,

    }
}

我希望用户名属性在创建表时是唯一的(即生成迁移时具有唯一约束)。可以这样做吗?

rust schema unique rust-diesel
1个回答
0
投票

不支持此功能。

Diesel 架构定义不是用于配置数据库表的一站式服务。在许多情况下,您需要手动调整柴油自动生成的迁移;这是其中之一。

© www.soinside.com 2019 - 2024. All rights reserved.