Jump to content

[SOLVED] Error #1452 - Cannot add or update a child row: a foreign key constrain


bulgaria_mitko

Recommended Posts

Can u please help me? im geting this error when im trying to insert a new record into my table user:

[code]Error

SQL:

INSERT INTO users( UserID, Username,
PASSWORD , FirstName, LastName, EmailAddress, PostAddress, City, PhoneNumber, Admin, Allowed, UserTypeID )
VALUES (
'1', '***********', '123', 'xxxxxxxxx', 'yyyyyyyy', '**********@yahoo.com', 'zzzzzzzzzzz', 'hhhhhhhh', '1234567890', 'TRUE', 'TRUE', '1'
)

MySQL replay: Documentury
#1452 - Cannot add or update a child row: a foreign key constraint fails (`nimatest/users`, CONSTRAINT `users_ibfk_5` FOREIGN KEY (`UserID`) REFERENCES `reviews` (`UserID`) ON DELETE CASCADE) [/code]

i have those tables:

[b]reviews table:[/b]

ReviewID 
ProductID
UserID
ReviewDate
Review
Online

[b]users table:[/b]

UserID 
Username
Password
FirstName
LastName
EmailAddress
PostAddress
City
PhoneNumber
Admin
Allowed
UserTypeID

and [b]usertype table:[/b]

UserTypeID
UserType


and the connection between those tables are:

[i]reviews->UserID REFER users->USERID  ON DELETE 'nothing selected' ON UPDATE 'nothing selected'
users->UserID REFER reviews->UserID  ON DELETE 'CASCADE'          ON UPDATE 'nothing selected'
users->UserTypeID REFER usertype->UserTypeID ON DELETE 'nothing selected' ON UPDATE 'nothing selected'[/i]

can u help me pls? thank you very much!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.