Subject | RE: [firebird-support] Error restoring - foreign key reference does not exist |
---|---|
Author | Svein Erling Tysvær |
Post date | 2013-05-06T08:23:16Z |
>When trying to restore a database, I am receiving the following error message in the restore log:Hi Bob!
>
>gbak: activating and creating deferred index
>FK_USER_DASHBOARD_ELEMENT_TO_US
>
>gbak:cannot commit index FK_USER_DASHBOARD_ELEMENT_TO_US
>
>gbak: ERROR:violation of FOREIGN KEY constraint "FK_USER_DASHBOARD_ELEMENT_TO_US" on table "USER_DASHBOARD_ELEMENT"
>
>gbak: ERROR: Foreign key reference target does not exist
>
>CREATE TABLE USER_DASHBOARD (
> USER_DASHBOARD_ID INTEGER NOT NULL,
> USER_ID INTEGER NOT NULL,
> NAME VARCHAR(40),
> INS_DATE DATE,
> GRID_ROW_COUNT INTEGER,
> GRID_COL_COUNT INTEGER);
>
>CREATE TABLE USER_DASHBOARD_ELEMENT (
> USER_DASHBOARD_ELEMENT_ID INTEGER NOT NULL,
> USER_DASHBOARD_ID INTEGER NOT NULL,
> DASHBOARD_ELEMENT_ID INTEGER NOT NULL,
> DISPLAY_ROW INTEGER,
> DISPLAY_COL INTEGER,
> INS_DATE DATE,
> REMOTE_INSTALLATION_ID INTEGER);
>
>ALTER TABLE USER_DASHBOARD_ELEMENT
>ADD CONSTRAINT FK_USER_DASHBOARD_ELEMENT_TO_US FOREIGN KEY(USER_DASHBOARD_ID)
>REFERENCES USER_DASHBOARD (USER_DASHBOARD_ID) ON DELETE CASCADE;
>
>I have verified that there are no entries in USER_DASHBOARD_ELEMENT that do not have a foreign key:
>
>select e.user_dashboard_element_id, count(u.user_dashboard_id)
>from user_dashboard_element e
>left join user_dashboard u on (u.user_dashboard_id = e.user_dashboard_id)
>group by 1
>having count(u.user_dashboard_id) = 0
>
>I have also verified that the index that supports this foreign key is in fact active. I'm not sure what
>the error message means in this case - is there an error or not?
Is USER_DASHBOARD.USER_DASHBOARD_ID defined as the primary key or a unique key (I don't think a unique index is sufficient)?
As for verifying no unreferenced entries, I'd rather use a simpler query:
select e.user_dashboard_element_id
from user_dashboard_element e
left join user_dashboard u on u.user_dashboard_id = e.user_dashboard_id
where u.user_dashboard_id is null
HTH,
Set