I have such structure of db http://pikucha.ru/icFsc (I can't add pictures here)
Some addresses my not have a metro (other tables have the same problem, for example "user" may not have an address, but there is constraint in "user" table)
If I add a record in mysql it's ok. If I do the same thing using yii I get an error
Cannot add or update a child row: a foreign key constraint fails (
address
, CONSTRAINT fk_Address_Area1
FOREIGN KEY (area_id
) REFERENCES area
(id
) ON UPDATE NO ACTION)
So, what's the problem in?
This is because you relation doesn't allow
NULL
values in the column. You have to edit the specific column, and check theempty
checkbox. Then MySQL will allowNULL
values.This error can occur due to some reasons as mentioned below
1. Data Types may not be the same for fk and pk.
2. Size may not be the same of fk and pk
3. type may be different like unsigned, binary,unsigned binary and null
4. The value you are trying to put in city does not occur in area table