Skip to content

Latest commit

 

History

History
47 lines (37 loc) · 1.39 KB

11_updating_entity.md

File metadata and controls

47 lines (37 loc) · 1.39 KB

Updating the entity

Now that we have the password field in our migration and in our database, we need to update our entity to reflect that change.

This is pretty simple. We simply rerun the entity creation command again.

sea-orm-cli generate entity -o entity/src

We are simply regenerating the entity. Since we already have an entity from before, and we only added the migration for the password field, the regenerated entity remains unchanged except the newly added field. If you were using Git, you would see only the password field in the diff.

Here's the regenerated entity,

//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0

use sea_orm::entity::prelude::*;
use serde::Serialize;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize)]
#[sea_orm(table_name = "user")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i32,
    #[sea_orm(unique)]
    pub username: String,
    pub firstname: Option<String>,
    pub lastname: Option<String>,
    #[sea_orm(unique)]
    pub email: String,
    pub password: String,   // new, just added
    pub is_active: Option<bool>,
    pub last_login: Option<DateTime>,
    pub date_joined: Option<DateTime>,
    pub created_at: Option<DateTime>,
    pub updated_at: Option<DateTime>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}