feat: Use TableCreateStatement::foreign_key
for foreign keys
Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
parent
3d086e511c
commit
7ef02d05d0
2 changed files with 18 additions and 8 deletions
|
@ -21,6 +21,8 @@
|
|||
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
use crate::create_users_table::Users;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
|
@ -39,10 +41,13 @@ impl MigrationTrait for Migration {
|
|||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(InChatRequests::RecipientId)
|
||||
.big_integer()
|
||||
.not_null(),
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-in_chat_requests-users")
|
||||
.from(InChatRequests::Table, InChatRequests::RecipientId)
|
||||
.to(Users::Table, Users::Id)
|
||||
.on_update(ForeignKeyAction::NoAction)
|
||||
.on_delete(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.col(ColumnDef::new(InChatRequests::Sender).string().not_null())
|
||||
.col(
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
use crate::create_users_table::Users;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
|
@ -39,10 +41,13 @@ impl MigrationTrait for Migration {
|
|||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(OutChatRequests::SenderId)
|
||||
.big_integer()
|
||||
.not_null(),
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-out_chat_requests-users")
|
||||
.from(OutChatRequests::Table, OutChatRequests::SenderId)
|
||||
.to(Users::Table, Users::Id)
|
||||
.on_update(ForeignKeyAction::NoAction)
|
||||
.on_delete(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(OutChatRequests::Recipient)
|
||||
|
|
Loading…
Reference in a new issue