Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7762307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:21:59+00:00 2026-06-01T14:21:59+00:00

I’m building a simple code-first MVC 3 blog like application. My model has three

  • 0

I’m building a simple code-first MVC 3 blog like application. My model has three tables, user, comment, and tutorial. The comment table has a FK for both user and tutorial. Tutorial has also a foreign key for user.

When I run the program I get the following error:

Introducing FOREIGN KEY constraint 'FK_Comments_Users_UserID' on table 'Comments' 
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. See previous errors.

It seems like the problem is being caused by something called cascading deletes. Microsoft’s solution to this is to have better DB design, http://support.microsoft.com/kb/321843. But this DB seems to be about as simple as you can get.

I’ve found a few other posts (Entity Framework Code first – FOREIGN KEY constraint problem) which seem to address this issue by adding a the following code in my db context class:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{

 modelBuilder.Entity<User>()
                .HasMany(u => u.Comments)
                .HasRequired(c => c.User)
                .HasForeignKey(c => c.UserId)
                .WillCascadeOnDelete(false);
 }

Unfortunately, Visual Studio gets mad at the syntax at ‘.HasRequired’ The actual error is “Error 1 ‘System.Data.Entity.ModelConfiguration.Configuration.ManyNavigationPropertyConfiguration’ does not contain a definition for ‘HasRequired’ and no extension method ‘HasRequired’ accepting a first argument of type ‘System.Data.Entity.ModelConfiguration.Configuration.ManyNavigationPropertyConfiguration’ could be found (are you missing a using directive or an assembly reference?)”

It seems like there is something simple here that I am missing. How can I restructure my database better or how can I solve this cyclical redundancy problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:22:01+00:00Added an answer on June 1, 2026 at 2:22 pm

    Use the WithRequired method instead of HasRequired

     modelBuilder.Entity<User>()
                    .HasMany(u => u.Comments)
                    .WithRequired(c => c.User)
                    .HasForeignKey(c => c.UserId)
                    .WillCascadeOnDelete(false);
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.