Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Please help with an UPDATE statement conflicted with the FOREIGN KEY constraint problem

Please help with an UPDATE statement conflicted with the FOREIGN KEY constraint problem

Scheduled Pinned Locked Moved Database
helpdatabasesql-serversysadminregex
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AlexanderBlade
    wrote on last edited by
    #1

    Hi can someone help me to solve a foreign key constraint problem? I’m using using Web Developer 2010 Express with mvc3. When my view loads I can create an object by clicking on the Create button but on the edit page, I click on save button and get an error message: That says my UPDATE statement conflicted with the FOREIGN KEY constraint giving the tables relationship and the column. Here’s what I’ve tried so far: I researched and found that this error is a bug in SQL Server 7.0. but I'm using Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 I found another tip that suggested that the id field in the main table is perhaps being called before the id fields of the associated table(s) was created. I tried changing the order by seeding all the other tables with data before my main table in my DBInitializer class. I also changed the order in my DBContext class… same error. Finally I decided to change the relationship directly in the database. I removed the relationship and created a new one (had to add fields in the main table to match the number of columns in the associated table). Nothing worked. I then removed the SetInitializer line from my Global.asax and created all tables from scratch directly in the database and as I created them, I found that I had to add data to the associated tables before adding stuff to my main table which seems to support an earlier suggestion but I still got the error message. I then changed my SetInitializer back to seed the tables still got the same error. I have no problems when I click the “Create” button, only “Save” on the Edit page. Any help would be greatly appreciated.

    L 1 Reply Last reply
    0
    • A AlexanderBlade

      Hi can someone help me to solve a foreign key constraint problem? I’m using using Web Developer 2010 Express with mvc3. When my view loads I can create an object by clicking on the Create button but on the edit page, I click on save button and get an error message: That says my UPDATE statement conflicted with the FOREIGN KEY constraint giving the tables relationship and the column. Here’s what I’ve tried so far: I researched and found that this error is a bug in SQL Server 7.0. but I'm using Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 I found another tip that suggested that the id field in the main table is perhaps being called before the id fields of the associated table(s) was created. I tried changing the order by seeding all the other tables with data before my main table in my DBInitializer class. I also changed the order in my DBContext class… same error. Finally I decided to change the relationship directly in the database. I removed the relationship and created a new one (had to add fields in the main table to match the number of columns in the associated table). Nothing worked. I then removed the SetInitializer line from my Global.asax and created all tables from scratch directly in the database and as I created them, I found that I had to add data to the associated tables before adding stuff to my main table which seems to support an earlier suggestion but I still got the error message. I then changed my SetInitializer back to seed the tables still got the same error. I have no problems when I click the “Create” button, only “Save” on the Edit page. Any help would be greatly appreciated.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      To really understand how to solve this problem, you must know what commands are executed against your database. One way to solve this issue is to turn on CASCADE UPDATE in your foreign key definition.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups