TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ozdemir Selcuk
NA
36
579
I'm getting this error while updating the db
Aug 24 2020 1:41 PM
protected
override
void
OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(
@
"Server=AHMET;Database=test;Trusted_Connection=True"
);
}
public
DbSet<Product> Products {
get
;
set
; }
public
DbSet<ProductFavorite> ProductFavorites{
get
;
set
; }
public
DbSet<ProductImage> ProductImages {
get
;
set
; }
public
DbSet<Category> Categories {
get
;
set
; }
public
DbSet<SubCategory> SubCategories {
get
;
set
; }
public
DbSet<Member> Members {
get
;
set
; }
public
DbSet<User> Users {
get
;
set
; }
public
DbSet<Blog> Blogs {
get
;
set
; }
protected
override
void
OnModelCreating(ModelBuilder modelBuilder)
{
base
.OnModelCreating(modelBuilder);
}
public
class
Category
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public
Guid CategoryId {
get
;
set
; }
[Required]
[DisplayName(
"Category"
)]
public
string
Name {
get
;
set
; }
public
virtual
IList<SubCategory> SubCategory {
get
;
set
; }
}
public
class
SubCategory
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public
Guid SubCategoryId {
get
;
set
; }
[Required]
[DisplayName(
"Subcategory"
)]
public
string
Name {
get
;
set
; }
[DisplayName(
"Category"
)]
public
Guid CategoryId {
get
;
set
; }
[ForeignKey(
"CategoryId"
)]
public
virtual
Category Category {
get
;
set
; }
public
virtual
IList<Product> Products {
get
;
set
; }
}
I give migrations the update-database command, I get the following error:
Error Number:1767,State:0,Class:16 "Foreign key 'FK_Products_Categories_CategoryId' references invalid table 'Categories'. Could not create constraint. See previous errors."
Thanks in advance for your interest.
Reply
Answers (
1
)
Asp.net mvc - how to show rich text without the html tags?
Please Help me in this and upload full method i am a beginner