(7ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [Posts] (
[Id] int NOT NULL IDENTITY,
[Title] nvarchar(100) NOT NULL,
[Text] nvarchar(max) NOT NULL,
[ImageUrl] nvarchar(255) NULL,
[UserId] int NOT NULL,
[PostStatisticsId] int NOT NULL,
[TopicOfPostId] int NOT NULL,
[CategoryId] int NOT NULL,
CONSTRAINT [PK_Posts] PRIMARY KEY ([Id]),
CONSTRAINT [FK_Posts_Categories_CategoryId] FOREIGN KEY ([CategoryId]) REFERENCES [Categories] ([Id]) ON DELETE CASCADE,
CONSTRAINT [FK_Posts_PostStatistics_PostStatisticsId] FOREIGN KEY ([PostStatisticsId]) REFERENCES [PostStatistics] ([Id]) ON DELETE CASCADE,
CONSTRAINT [FK_Posts_TopicsOfPosts_TopicOfPostId] FOREIGN KEY ([TopicOfPostId]) REFERENCES [TopicsOfPosts] ([Id]) ON DELETE CASCADE,
CONSTRAINT [FK_Posts_Users_UserId] FOREIGN KEY ([UserId]) REFERENCES [Users] ([Id]) ON DELETE CASCADE
);
Introducing FOREIGN KEY constraint 'FK_Posts_TopicsOfPosts_TopicOfPostId' on table 'Posts' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Could not create constraint or index. See previous errors.
using Forum_MVC.Data.Entities;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
public class Post
{
public int Id { get; set; }
[Required(ErrorMessage = "The 'Title' field is required.")]
[StringLength(100, MinimumLength = 3, ErrorMessage = "Title must be between 3 and 100 characters.")]
public string Title { get; set; }
[Required(ErrorMessage = "The 'Text' field is required.")]
public string Text { get; set; }
[MaxLength(255, ErrorMessage = "Image URL cannot exceed 255 characters.")]
public string? ImageUrl { get; set; }
[Required(ErrorMessage = "The 'UserId' field is required.")]
public int UserId { get; set; }
public int PostStatisticsId { get; set; }
[ForeignKey("PostStatisticsId")]
public PostStatistics PostStatistics { get; set; }
[ForeignKey("UserId")]
public User User { get; set; }
public int TopicOfPostId { get; set; }
[ForeignKey("TopicOfPostId")]
public TopicOfPost Topic { get; set; }
public ICollection<Comment> Comments { get; set; }
public int CategoryId { get; set; }
[ForeignKey("CategoryId")]
public Category Categories { get; set; }
}
using Forum_MVC.Data.Entities;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
public class TopicOfPost
{
public int Id { get; set; }
[Required(ErrorMessage = "The 'Name' field is required.")]
[StringLength(100, MinimumLength = 3, ErrorMessage = "Name must be between 3 and 100 characters.")]
public string Name { get; set; }
[MaxLength(255, ErrorMessage = "Description cannot exceed 255 characters.")]
public string Description { get; set; }
[Required(ErrorMessage = "The 'UserId' field is required.")]
public int UserId { get; set; }
// Active, Suspended
public string VisibilityStatus { get; set; }
[ForeignKey("UserId")]
public User User { get; set; }
public ICollection<Post> Posts { get; set; }
}
Буду очень благодарна за помощь)
ну так написано же вроде Introducing FOREIGN KEY constraint 'FK_Posts_TopicsOfPosts_TopicOfPostId' on table 'Posts' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Обсуждают сегодня