1

I can't figure out this error:

Cannot add or update a child row: a foreign key constraint fails (freight.rates_detail, CONSTRAINT rates_detail_ibfk_2 FOREIGN KEY (component_id) REFERENCES computation (id) ON UPDATE CASCADE)

Here's what I'm trying to do(from the log):

INSERT INTO freight.rates_detail(rate_id,component_id,uom,rate,inc_or) values(0821,01,00,011.00,'Y')

I repeatedly looked and looked and reviewed the values of id in table computation and the value in that case: 01 exists.

What's the problem with this?

9
  • What is the data type of your component_id column? Commented Sep 16, 2013 at 13:49
  • 1
    Check if component_id column is the same type adn length as the id column in computation. Commented Sep 16, 2013 at 13:49
  • @eggyal: they're all int with length: 11 Commented Sep 16, 2013 at 13:51
  • 2
    Just a side note (not related to your problem): an int does not have "a length". The 11 is only a hint for a client application to be used when displaying the data. It does not limit the possible values in any way. You can store the same values in an int(1) and an int(11) Commented Sep 16, 2013 at 13:56
  • 1
    @eggshot: Yes, that will be the problem. MySQL requires both tables to use the same storage engine (and not MyISAM) in order for foreign key constraints to work. Commented Sep 16, 2013 at 14:14

1 Answer 1

3

i just found out that the reference table is MyISAM not InnoDB will it affect?

Yes. As documented under Using FOREIGN KEY Constraints:

The parent and child tables must use the same storage engine.

It goes on to say:

For storage engines that do not support foreign keys (such as MyISAM), MySQL Server parses and ignores foreign key specifications.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.