Invalid foreign key errors on apply
Template has two tables with a relationship block_information and block_type. The apply tries to import data from block_information records before block_type giving these errors
Warning: Directus Error: Invalid foreign key for field "block_type" in collection "block_information". (Status: 400)
› {"collection":"block_information","field":"block_type","code":"INVALID_FOREIGN_KEY"}
there is more detail in the directus logs:
2024-12-17 02:09:40.652 UTC [139] ERROR: insert or update on table "block_information" violates foreign key constraint "block_information_block_type_foreign"
2024-12-17 02:09:40.652 UTC [139] DETAIL: Key (block_type)=(2) is not present in table "block_types".
Running a 2nd time seems to work but would be better if it could create dependant data first
Is this one of your own templates?
- If so can you tell me what SQL database you're using? (MySQL, Postgres, etc?)
- What type of relationship do you have setup?
Edited: Updated with some better info
We are currently seeing these issues as well when extracting from our directus cloud instance and applying to our local docker instance. We're using Postgres.
Loading 12 folders... done
Loading 270 files... done
› Warning: Directus Error: Invalid foreign key for field "pages_order_confirmation_id" in collection
› "pages_order_confirmation_blocks". (Status: 400) {"collection":"pages_order_confirmation_blocks","field":"pages_or
› der_confirmation_id","code":"INVALID_FOREIGN_KEY"}
› Warning: Directus Error: Invalid foreign key for field "pages_product_id" in collection "pages_product_blocks".
› (Status: 400) {"collection":"pages_product_blocks","field":"pages_product_id","code":"INVALID_FOREIGN_KEY"}
Loading data for 103 collections... done
-- Request failed. Retrying after 1000ms
-- Retrying job (attempt 1)
-- Request failed. Retrying after 2000ms
-- Retrying job (attempt 2)
-- Request failed. Retrying after 4000ms
-- Retrying job (attempt 3)
-- Max retries reached, not retrying further
› Warning: Directus Error: Cannot read properties of undefined (reading 'is_primary_key') (Status: 500)
› {"code":"INTERNAL_SERVER_ERROR"}
-- Request failed. Retrying after 1000ms
-- Retrying job (attempt 1)
-- Request failed. Retrying after 2000ms
-- Retrying job (attempt 2)
-- Request failed. Retrying after 4000ms
-- Retrying job (attempt 3)
-- Max retries reached, not retrying further
...
-
pages_order_confirmationID is of type UUID -
Results in our
blocksfield with invalid items -
blocks field is set up as a builder m2a type
pages_order_confirmation_blocksbelow
Reference to Directus guide about this implementation: https://docs.directus.io/guides/headless-cms/reusable-components.html
closing because this is several years old