Why this error shows up?

My logic is if the user 1 that follows user 2, and user 1 account got deleted the following for the user 2 will be removed same goes for the following table

CREATE TABLE [Followers] 
(
    [id] int NOT NULL PRIMARY KEY IDENTITY(1,1),
    [userId] int NOT NULL, 
    [followerID] int NOT NULL,

    CONSTRAINT userIdFollowed 
        FOREIGN KEY (userId) REFERENCES [User](id) 
            ON DELETE CASCADE
            ON UPDATE CASCADE, 

    CONSTRAINT userIdFollower 
        FOREIGN KEY (followerID) REFERENCES [User](id) 
            ON DELETE CASCADE 
            ON UPDATE CASCADE,
);

CREATE TABLE [Following] 
(
    [id] int NOT NULL PRIMARY KEY IDENTITY(1,1), 
    [userId] int NOT NULL, 
    [followingID] int NOT NULL,

    CONSTRAINT userIdFollow 
        FOREIGN KEY (userId) REFERENCES [User](id) 
            ON DELETE CASCADE 
            ON UPDATE NO ACTION, 

    CONSTRAINT userIdFollowing 
        FOREIGN KEY (followingID) REFERENCES [User](id) 
            ON DELETE CASCADE
            ON UPDATE NO ACTION,
);
1

There are 1 best solutions below

0
Aziz On

l found out that l was repeating myself in the code and that how l fixed it

CREATE TABLE [Followers] (
 [id] int NOT null PRIMARY KEY IDENTITY(1,1),
 [userId] int not null, 
[followerID] int not null,

 CONSTRAINT userIdFollowed FOREIGN KEY (userId) REFERENCES [User](id) ON DELETE cascade ON UPDATE cascade, 

CONSTRAINT userIdFollower FOREIGN KEY (followerID) REFERENCES [User](id) ON DELETE no action ON UPDATE no action,
 );

 CREATE TABLE [Following] ( 
[id] int NOT null PRIMARY KEY IDENTITY(1,1), 
[userId] int not null, 
[followingID] int not null,

 CONSTRAINT userIdFollow FOREIGN KEY (userId) REFERENCES [User](id) ON DELETE cascade ON UPDATE cascade, 

CONSTRAINT userIdFollowing FOREIGN KEY (followingID) REFERENCES [User](id) ON DELETE no action ON UPDATE no action,
 );