Şimdi Ara

Migrations ile db'yi update etmeye çalıştığımda aşağıdaki hatayı alıyorum.

Daha Fazla
Bu Konudaki Kullanıcılar: Daha Az
2 Misafir - 2 Masaüstü
5 sn
3
Cevap
0
Favori
195
Tıklama
Daha Fazla
İstatistik
  • Konu İstatistikleri Yükleniyor
0 oy
Öne Çıkar
Sayfa: 1
Giriş
Mesaj
  • {

           public class Category

           {

           [Key]

           [DatabaseGenerated(DatabaseGeneratedOption.Identity)]

           public Guid Id { 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 Id { 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; }

       }


     public class Product

       {

           [Key]

           [DatabaseGenerated(DatabaseGeneratedOption.Identity)]

           public int ProductId{ get; set; }

           public string ProductNumber { get; set; }

           public string Name{ get; set; }

           public string Description { get; set; }

           public double Price { get; set; }

           public int Stock{ get; set; }

           public bool IsApproved { get; set; }

           public bool IsHome { get; set; }

           public DateTime CreatedDate{ get; set; }

           public List<ProductImage> ProductImages { get; set; }


           [DisplayName("Subcategory")]

           public Guid SubCategoryId { get; set; }

           [ForeignKey("SubCategoryId")]

           public virtual SubCategory SubCategories { get; set; }

       }

    }



    DBContext :


      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; }



    Migrations ile dbyi update etmeye çalıştığımda aşağıdaki hatayı alıyorum.

    Yardımcı olur musunuz ?

    Foreign key 'FK_Products_Categories_CategoryId' references invalid table 'Categories'.

    Could not create constraint. See previous errors.








  • işte hata söylüyor. Categories diye bir tablo bulamamış. Ayrıca kategoriyi tek tablo ile yapabilirsin. Ayrıca guid kullanımı kullanacağın database ve index bağlı olarak sorun oluşturur. bigint kullanmak daha iyi olabilir.

    https://stackoverflow.com/a/11938495
  • 
Sayfa: 1
- x
Bildirim
mesajınız kopyalandı (ctrl+v) yapıştırmak istediğiniz yere yapıştırabilirsiniz.