Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

SQL - Foreign Key, constraints error..

  • 17-04-2009 10:53pm
    #1
    Registered Users, Registered Users 2 Posts: 2,236 ✭✭✭


    Ok,

    I'm stumped! I'm trying to setup a foreign key realtionship as shown below..
    I keep getting the same error which is annoying. I've done this kind of thing with other fields but this just doesn't seem to be working at all...

    I'm sure it's something small but what am I doing wrong here??:o
    SQL query:
    
    ALTER TABLE `users` ADD FOREIGN KEY ( `profile_photo` ) REFERENCES `iflicks`.`photos` (
    `photo_id`
    ) ON DELETE CASCADE ON UPDATE CASCADE ;
    
    MySQL said: Documentation
    #1452 - Cannot add or update a child row: a foreign key constraint fails (`iflicks`.`#sql-4dc_221`, CONSTRAINT `#sql-4dc_221_ibfk_1` FOREIGN KEY (`profile_photo`) REFERENCES `photos` (`photo_id`) ON DELETE CASCADE ON UPDATE CASCADE) 
    

    Thanks..


Comments

  • Registered Users, Registered Users 2 Posts: 981 ✭✭✭fasty


    If the FK constraint was in place, one of the rows would violate it so when you try to alter the table. Although that's a massive assumption on my part because I don't know if MySQL is that "strict". Or it could be a circular dependency?


  • Registered Users, Registered Users 2 Posts: 2,236 ✭✭✭techguy


    fasty wrote: »
    If the FK constraint was in place, one of the rows would violate it so when you try to alter the table. Although that's a massive assumption on my part because I don't know if MySQL is that "strict". Or it could be a circular dependency?

    You are correct, I found something just after I posted..

    I just cleared the data in both tables and it worked fine..now I have problems adding rows but thats probably something just as trivial..

    Thanks.


Advertisement