Subject | Re: [firebird-support] Foreign key violation - but why??? |
---|---|
Author | Yew Mun |
Post date | 2005-03-08T11:03:01Z |
You have to make ANMELDUNG_ID of table XPERT_ANMELDUNGEN be the primary key.
try
alter table XPERT_ANMELDUNGEN add constraint pk_XPERT_ANMELDUNGEN
primary key(ANMELDUNG_ID);
before you add the foreign key constraints.
Uwe Grauer wrote:
Tai Yew Mun
Principal Software Architect
Airquace Technologies Pte Ltd
Tel: 65336461
Email: yewmun@...
try
alter table XPERT_ANMELDUNGEN add constraint pk_XPERT_ANMELDUNGEN
primary key(ANMELDUNG_ID);
before you add the foreign key constraints.
Uwe Grauer wrote:
>Bjoern Reimer wrote:--
>
>
>
>>Hi,
>>
>> (Firebird 1.5.1 CS on Linux)
>>
>> Here is my situation:
>>
>> Two tables with one record each. I want to create a foreign key
>> constraint from one to the other.
>>
>>
>>CREATE TABLE XPERT_ANMELDUNGEN (
>> ANMELDUNG_ID BIGINT NOT NULL,
>> PRUEFUNGSART_ID INTEGER NOT NULL,
>> PERSON_ID INTEGER NOT NULL,
>> XP_TERM_ID INTEGER NOT NULL,
>> ZAHLUNGSSTATUS SMALLINT DEFAULT 0 NOT NULL
>>);
>>
>>INSERT INTO XPERT_ANMELDUNGEN
>>(ANMELDUNG_ID,PRUEFUNGSART_ID,PERSON_ID,XP_TERM_ID,ZAHLUNGSSTATUS)
>>VALUES (1,1,6,6,0);
>>
>>
>>CREATE TABLE XPERT_ZAHLUNGEN (
>> ID BIGINT NOT NULL,
>> REF_ANMELDUNG_ID BIGINT,
>> REF_ZAHLUNGSART SMALLINT,
>> ZEITPUNKT TIMESTAMP NOT NULL
>>);
>>
>>
>>INSERT INTO XPERT_ZAHLUNGEN (ID,REF_ANMELDUNG_ID,REF_ZAHLUNGSART,ZEITPUNKT) VALUES (30,1,1,'7-MAR-2005 00:00:00');
>>
>>
>> And
>>
>>
>>
>>
>>
>At this point, try disconnectiong ALL connections to the Database,
>do a fresh connect and than add the following constraint.
>Metadata updates like this should only be done if you have ONE
>connection to your db.
>
>
>
>>alter table XPERT_ZAHLUNGEN add constraint
>>FK_XPERT_ZAHLUNGEN_REF_ANMELDUN foreign key (REF_ANMELDUNG_ID)
>>references XPERT_ANMELDUNGEN(ANMELDUNG_ID)
>>
>> returns me
>>
>>violation of FOREIGN KEY constraint "".
>>violation of FOREIGN KEY constraint "PK_XPERT_ANMELDUNGEN" on table "XPERT_ANMELDUNGEN".
>>
>>
>> I've the same result in this table with REF_ZAHLUNGSART which points
>> to another table of course....
>>
>> I've tried it without any records in XPERT_ZAHLUNGEN with the same
>> result...
>>
>> Any ideas?
>>
>>
>>
>> Björn
>>
>>
>>
>>
>>
>
>
>
>
>Yahoo! Groups Links
>
>
>
>
>
>
>
>
>
>
>
>
Tai Yew Mun
Principal Software Architect
Airquace Technologies Pte Ltd
Tel: 65336461
Email: yewmun@...