Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,335
    Thanks
    5
    Thanked 363 Times in 360 Posts

    phpMyadmin Questions

    Hi, I haven't dealt with creating tables in a long time, and even though this will be a coldfusion query on a MySQL database, I am in the middle of learning PHP so I thought I'd spend time learning how to admin databases using phpMyadmin.

    I will say I also use Navicat as well. My problem is I'm working on a database for car lamp applications. So as of now I have 2 tables: carMaker and carMake. carMake is different models of a manufacture brand, so for instance Camaro, Chevelle, Belair all are Chevrolets. Falcon, Fairlane, Taurus all Fords.

    I'll just show my table structures before describing my issue.

    modelID model makerID
    1 Camaro 2
    2 Chevelle 2
    3 Falcon 4
    4 Fairlane 4
    5 Challenger 5

    This was created in Navicat. When I try to insert records using phpmyadmin, I get an error:

    PHP Code:
    INSERTINTO`rlbulbs`.`carmake` (

     `
    modelID` ,
     `
    model` ,
     `
    makerID
    )
    VALUES (
     
    '','Firebird','8'
    )
     
    MySQL said
    #1452 - Cannot add or update a child row: a foreign key constraint fails (`rlbulbs`.`carmake`, CONSTRAINT `carmake_ibfk_1` FOREIGN KEY (`modelID`) REFERENCES `carmaker` (`makerID`) ON UPDATE NO ACTION) 
    Again, please excuse my newbness with databases, in particular with phpmyadmin, but any tips and help would be greatly appreciated.
    Teed

  • #2
    New Coder
    Join Date
    Jan 2010
    Posts
    29
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Hmm well it looks like you have a foreign key constraint. That is you're referencing a value that doesn't exist in its reference table.

    Example:

    hosts:

    host_id
    host_name

    uptime:

    host_id
    uptime_value

    If I insert a host_id into the uptime table and the host_id doesn't exist in the hosts table and a foreign key contraint exists I'll get that error you're getting.
    Nerd Stuff (code, rrdtool, monitoring, etc):

    blog.anthonyhurst.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •