Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying snapshot leads to foreign key error #13323

Closed
derkoenigeu opened this issue May 16, 2022 · 1 comment
Closed

Applying snapshot leads to foreign key error #13323

derkoenigeu opened this issue May 16, 2022 · 1 comment

Comments

@derkoenigeu
Copy link

derkoenigeu commented May 16, 2022

Describe the Bug

We have encountered the following bug:
As of using the command 'npx directus schema apply --yes /path/to/snapshot.yml' we are getting the following error:

Error: Invalid foreign key in field "group".
at foreignKeyViolation (/directus/node_modules/directus/dist/exceptions/database/dialects/mysql.js:138:12)
at extractError (/directus/node_modules/directus/dist/exceptions/database/dialects/mysql.js:31:20)
at translateDatabaseError (/directus/node_modules/directus/dist/exceptions/database/translate.js:47:53)
at /directus/node_modules/directus/dist/services/items.js:102:68
at processTicksAndRejections (node:internal/process/task_queues:96:5)

To Reproduce

To reproduce try to use the following for the snapshot.yml:

version: 1
directus: 9.10.0
collections:
  - collection: Test1
    meta:
      collection: Test1
      icon: null
      note: null
      display_template: null
      hidden: false
      singleton: false
      translations: null
      archive_field: null
      archive_app_filter: true
      archive_value: null
      unarchive_value: null
      sort_field: null
      accountability: all
      color: null
      item_duplication_fields: null
      sort: 1
      group: Test_folder
      collapse: open
    schema:
      name: Test1
      schema: db
      comment: ''
      collation: utf8mb4_general_ci
      engine: InnoDB
  - collection: Test2
    meta:
      collection: Test2
      icon: null
      note: null
      display_template: null
      hidden: false
      singleton: false
      translations: null
      archive_field: null
      archive_app_filter: true
      archive_value: null
      unarchive_value: null
      sort_field: null
      accountability: all
      color: null
      item_duplication_fields: null
      sort: 2
      group: Test_folder
      collapse: open
    schema:
      name: Test2
      schema: db
      comment: ''
      collation: utf8mb4_general_ci
      engine: InnoDB
  - collection: Test_folder
    meta:
      collection: Test_folder
      icon: folder
      note: null
      display_template: null
      hidden: false
      singleton: false
      translations: null
      archive_field: null
      archive_app_filter: true
      archive_value: null
      unarchive_value: null
      sort_field: null
      accountability: all
      color: null
      item_duplication_fields: null
      sort: 1
      group: null
      collapse: open
    schema: null
fields:
  - collection: Test1
    field: id
    type: integer
    schema:
      name: id
      table: Test1
      data_type: int unsigned
      default_value: null
      generation_expression: null
      max_length: null
      numeric_precision: 10
      numeric_scale: 0
      is_generated: false
      is_nullable: false
      is_unique: false
      is_primary_key: true
      has_auto_increment: true
      foreign_key_column: null
      foreign_key_table: null
      comment: ''
    meta:
      collection: Test1
      field: id
      special: null
      interface: input
      options: null
      display: null
      display_options: null
      readonly: true
      hidden: true
      sort: null
      width: full
      translations: null
      note: null
      conditions: null
      required: false
      group: null
      validation: null
      validation_message: null
  - collection: Test1
    field: test_field_1
    type: string
    schema:
      name: test_field_1
      table: Test1
      data_type: varchar
      default_value: null
      generation_expression: null
      max_length: 255
      numeric_precision: null
      numeric_scale: null
      is_generated: false
      is_nullable: true
      is_unique: false
      is_primary_key: false
      has_auto_increment: false
      foreign_key_column: null
      foreign_key_table: null
      comment: ''
    meta:
      collection: Test1
      field: test_field_1
      special: null
      interface: input
      options: null
      display: null
      display_options: null
      readonly: false
      hidden: false
      sort: null
      width: full
      translations: null
      note: null
      conditions: null
      required: false
      group: null
      validation: null
      validation_message: null
  - collection: Test1
    field: test_field_2
    type: text
    schema:
      name: test_field_2
      table: Test1
      data_type: text
      default_value: null
      generation_expression: null
      max_length: 65535
      numeric_precision: null
      numeric_scale: null
      is_generated: false
      is_nullable: true
      is_unique: false
      is_primary_key: false
      has_auto_increment: false
      foreign_key_column: null
      foreign_key_table: null
      comment: ''
    meta:
      collection: Test1
      field: test_field_2
      special: null
      interface: input-rich-text-html
      options: null
      display: null
      display_options: null
      readonly: false
      hidden: false
      sort: null
      width: full
      translations: null
      note: null
      conditions: null
      required: false
      group: null
      validation: null
      validation_message: null
  - collection: Test1
    field: test_field_3
    type: boolean
    schema:
      name: test_field_3
      table: Test1
      data_type: boolean
      default_value: null
      generation_expression: null
      max_length: null
      numeric_precision: 3
      numeric_scale: 0
      is_generated: false
      is_nullable: true
      is_unique: false
      is_primary_key: false
      has_auto_increment: false
      foreign_key_column: null
      foreign_key_table: null
      comment: ''
    meta:
      collection: Test1
      field: test_field_3
      special:
        - cast-boolean
      interface: boolean
      options: null
      display: null
      display_options: null
      readonly: false
      hidden: false
      sort: null
      width: full
      translations: null
      note: null
      conditions: null
      required: false
      group: null
      validation: null
      validation_message: null
  - collection: Test2
    field: id
    type: integer
    schema:
      name: id
      table: Test2
      data_type: int unsigned
      default_value: null
      generation_expression: null
      max_length: null
      numeric_precision: 10
      numeric_scale: 0
      is_generated: false
      is_nullable: false
      is_unique: false
      is_primary_key: true
      has_auto_increment: true
      foreign_key_column: null
      foreign_key_table: null
      comment: ''
    meta:
      collection: Test2
      field: id
      special: null
      interface: input
      options: null
      display: null
      display_options: null
      readonly: true
      hidden: true
      sort: null
      width: full
      translations: null
      note: null
      conditions: null
      required: false
      group: null
      validation: null
      validation_message: null
  - collection: Test2
    field: test_field_2
    type: string
    schema:
      name: test_field_2
      table: Test2
      data_type: varchar
      default_value: null
      generation_expression: null
      max_length: 255
      numeric_precision: null
      numeric_scale: null
      is_generated: false
      is_nullable: true
      is_unique: false
      is_primary_key: false
      has_auto_increment: false
      foreign_key_column: null
      foreign_key_table: null
      comment: ''
    meta:
      collection: Test2
      field: test_field_2
      special: null
      interface: input
      options: null
      display: null
      display_options: null
      readonly: false
      hidden: false
      sort: null
      width: full
      translations: null
      note: null
      conditions: null
      required: false
      group: null
      validation: null
      validation_message: null
  - collection: Test2
    field: test_fiel_3
    type: uuid
    schema:
      name: test_fiel_3
      table: Test2
      data_type: char
      default_value: null
      generation_expression: null
      max_length: 36
      numeric_precision: null
      numeric_scale: null
      is_generated: false
      is_nullable: true
      is_unique: false
      is_primary_key: false
      has_auto_increment: false
      foreign_key_column: id
      foreign_key_table: directus_files
      comment: ''
    meta:
      collection: Test2
      field: test_fiel_3
      special:
        - file
      interface: file-image
      options: null
      display: null
      display_options: null
      readonly: false
      hidden: false
      sort: null
      width: full
      translations: null
      note: null
      conditions: null
      required: false
      group: null
      validation: null
      validation_message: null
  - collection: Test2
    field: test_field_4
    type: text
    schema:
      name: test_field_4
      table: Test2
      data_type: text
      default_value: null
      generation_expression: null
      max_length: 65535
      numeric_precision: null
      numeric_scale: null
      is_generated: false
      is_nullable: true
      is_unique: false
      is_primary_key: false
      has_auto_increment: false
      foreign_key_column: null
      foreign_key_table: null
      comment: ''
    meta:
      collection: Test2
      field: test_field_4
      special: null
      interface: input-rich-text-html
      options: null
      display: null
      display_options: null
      readonly: false
      hidden: false
      sort: null
      width: full
      translations: null
      note: null
      conditions: null
      required: false
      group: null
      validation: null
      validation_message: null
relations:
  - collection: Test2
    field: test_fiel_3
    related_collection: directus_files
    schema:
      table: Test2
      column: test_fiel_3
      foreign_key_table: directus_files
      foreign_key_column: id
      constraint_name: test2_test_fiel_3_foreign
      on_update: NO ACTION
      on_delete: SET NULL
    meta:
      many_collection: Test2
      many_field: test_fiel_3
      one_collection: directus_files
      one_field: null
      one_collection_field: null
      one_allowed_collections: null
      junction_field: null
      sort_field: null
      one_deselect_action: nullify

Errors Shown

Error: Invalid foreign key in field "group".
at foreignKeyViolation (/directus/node_modules/directus/dist/exceptions/database/dialects/mysql.js:138:12)
at extractError (/directus/node_modules/directus/dist/exceptions/database/dialects/mysql.js:31:20)
at translateDatabaseError (/directus/node_modules/directus/dist/exceptions/database/translate.js:47:53)
at /directus/node_modules/directus/dist/services/items.js:102:68
at processTicksAndRejections (node:internal/process/task_queues:96:5)

What version of Directus are you using?

9.10.0.

What version of Node.js are you using?

16.15.0 (whatever the official directus docker container uses)

What database are you using?

MySQL 8.0

What browser are you using?

Chrome

How are you deploying Directus?

Docker

@azrikahar
Copy link
Contributor

Duplicate of #9723, and has been resolved by #12198 (not released yet as of the time of this reply) 👍

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants