Foreign key

How should I set the foreign keys of a table?

In the method public function relations ()?

'comune1'=>array(self::HAS_MANY, 'anagrafe', 'COMUNE_COMUNE_ID') 

But sometimes gives me the error and sometimes not and why?

I was wrong to set the relation?

CDbCommand failed to execute the SQL statement: SQLSTATE[HY000]: General error: 20999 OCIStmtExecute: ORA-20999: TAPI-1005:Violata chiave esterna ANAGRA_COMUNE_FK della tabella ANAGRAFE