Yii Framework Forum: primary and foreign key in yii - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

primary and foreign key in yii foreign key validations in yii gii crud Rate Topic: -----

#1 User is offline   shaik 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 14-August 12

Posted 14 August 2012 - 07:34 AM

Hi everyone. am a new bee to yii framework

I have created two tables with two primary keys and one foreign key (reference of first table) and when I applied gii crud to those tables first one with out fk is ok . But the problem is if the id (10 eg) is not there in first table and trying add the non existing value(eg 10) in referencing table its giving error. I know the error is unless we dont have entries in main table we can enter the values in another table. When I apply crud operations using gii am getting error.

I want to know that how to handle that error.

Regards
Shaik
0

#2 User is offline   alirz23 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,012
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 14 August 2012 - 07:45 AM

shaik what error message you getting
0

#3 User is offline   shaik 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 14-August 12

Posted 14 August 2012 - 07:57 AM

I am getting this year when I try to add a group id of which is not there in first table(primary key).

CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`testyiiapp`.`explanationcontent`, CONSTRAINT `explanationcontent_ibfk_1` FOREIGN KEY (`groupid`) REFERENCES `explanationmaster` (`id`)). The SQL statement executed was: UPDATE `explanationcontent` SET `id`=:yp0, `groupid`=:yp1, `sequence`=:yp2, `exp_text`=:yp3 WHERE `explanationcontent`.`id`=8

Regards
Shaik
0

#4 User is offline   sunny lalwani 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 01-February 13
  • Location:Anand

Posted 01 February 2013 - 06:53 AM

Hello everybody,
I am beginner in yii framework.
I need help for implementing relationship between table in yii please give me the solution using example.
0

#5 User is offline   mirunho 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 19-December 12
  • Location:Gdansk, Poland

Posted 01 February 2013 - 09:08 AM

shaik did you try this command in phpmyadmin or something like this ?
@sunny welcome to forum, two links for You:
first to read:
http://www.yiiframew...en/database.arr
http://www.yiiframew..._many-relation/
0

#6 User is offline   developer! 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 110
  • Joined: 28-November 12

Posted 01 February 2013 - 09:47 AM

View Postshaik, on 14 August 2012 - 07:57 AM, said:

I am getting this year when I try to add a group id of which is not there in first table(primary key).

CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`testyiiapp`.`explanationcontent`, CONSTRAINT `explanationcontent_ibfk_1` FOREIGN KEY (`groupid`) REFERENCES `explanationmaster` (`id`)). The SQL statement executed was: UPDATE `explanationcontent` SET `id`=:yp0, `groupid`=:yp1, `sequence`=:yp2, `exp_text`=:yp3 WHERE `explanationcontent`.`id`=8

Regards
Shaik



Hi Shaikh,

you are trying to insert into your child table when u dont have related entry in your parent table. try to insert that parent id in your parent table. then you can add the same key id in your child table.
0

#7 User is offline   developer! 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 110
  • Joined: 28-November 12

Posted 01 February 2013 - 09:51 AM

View Postsunny lalwani, on 01 February 2013 - 06:53 AM, said:

Hello everybody,
I am beginner in yii framework.
I need help for implementing relationship between table in yii please give me the solution using example.



Hi Sunny,

Welcome to Yii Family. if you can tell us what you want to achieve..that'd be easy for someone to help you..

however find this link it helps..

http://www.yiiframew...s-for-newcomer/

http://www.yiiframew...ry-with-through

cheers!!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users