Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I define a unique constraint in a diesel schema attribute

This is my schema:

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,

    }
}

I want the username attribute to be unique when the table is created (that is, having the unique constraint when the migration is generated). Is it possible to do this?

like image 338
Drasungor Avatar asked Nov 19 '25 15:11

Drasungor


1 Answers

This is not supported.

The Diesel schema definitions are not a one-stop-shop for configuring your database tables. There are many situations where you'd need to manually adjust the auto-generated migrations from diesel; this being one of them.

like image 109
kmdreko Avatar answered Nov 21 '25 09:11

kmdreko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!