Subject [Ticket #388] [firebird-support] Re: Foreign key reference target does not exist. [FB 2.5 beta ...
Author Desarrollo
This is a notification from the Help Desk.




On Mar 07, 2014 @ 03:32 pm, adam.cirkic@ri.t-com.hr wrote:
Do you make FK over existing records?You probably already have old records in second table which refer to nonexistent PK in first table.Delete all old orphan records in second table, and then make FK.

--- In firebird-support@yahoogroups.com, "Isaac Bekheit" <isaac_cm@...> wrote:
>
> hello,
> I tried to create a foreign key but I always get this error:
>
> violation of FOREIGN KEY constraint "".
> violation of FOREIGN KEY constraint "FK_RES_TREEVIEW_1" on table "RES_TREEVIEW".
> Foreign key reference target does not exist.
>
> here is my two tables DDL:
>
> CREATE TABLE STYLES (
> STYLE_ID INTEGER DEFAULT -1 NOT NULL,
> STYLE_NAME VARCHAR(80) NOT NULL,
> BACK_COLOR VARCHAR(35),
> BACK_COLOR_ENABLED SMALLINT DEFAULT 0,
> FONT_STYLE_IS_UNDER SMALLINT DEFAULT 0,
> FONT_STYLE_IS_STRIKE SMALLINT DEFAULT 0,
> BITMAP_IMAGE BLOB SUB_TYPE 0 SEGMENT SIZE 80
> );
>
> ALTER TABLE STYLES ADD CONSTRAINT PK_STYLES1 PRIMARY KEY (STYLE_ID);
>
> ===============================================================
>
> CREATE TABLE RES_TREEVIEW (
> FOLDER_ID BIGINT NOT NULL,
> FOLDER_PARENT_ID BIGINT NOT NULL,
> FOLDER_NAME VARCHAR(100) NOT NULL,
> FOLDER_POSITION BIGINT NOT NULL,
> FOLDER_IMAGE_INDEX SMALLINT,
> FOLDER_FLAG BLOB SUB_TYPE 0 SEGMENT SIZE 80,
> FOLDER_ICON BLOB SUB_TYPE 0 SEGMENT SIZE 80,
> IS_FOLDER_CUSTOM_ICON SMALLINT DEFAULT 0,
> STYLE_ID INTEGER DEFAULT -1
> );
>
> ALTER TABLE RES_TREEVIEW ADD CONSTRAINT PK_RES_TREEVIEW PRIMARY KEY (FOLDER_ID);
>
> alter table RES_TREEVIEW
> add constraint FK_RES_TREEVIEW_1
> foreign key (STYLE_ID)
> references STYLES(STYLE_ID)
> on delete SET DEFAULT
> on update CASCADE
>
> ========================================================
> any advice ?
>
> Thanks
>

------
This is an automated response. Your issue has been noted. We'll be in touch soon.



Please reply to this email or visit the URL below with any additional details.

http://DANTOIN:9675/portal/view-help-request/388




[Non-text portions of this message have been removed]