开发者

Troubleshooting "Key column doesn't exist in table" when building from schema.yml

开发者 https://www.devze.com 2022-12-13 11:03 出处:网络
I have the following schema.yml file: Page: actAs: I18n: fields: [name,html,urlShortDesc] columns: name:开发者_开发问答 string

I have the following schema.yml file:

Page:
  actAs:
    I18n:
      fields: [name,html,urlShortDesc]
  columns:
    name:开发者_开发问答 string
    gender: 
      type: enum
      values: [html, photoGallery]
      default: html
    html: string
    urlShortDesc: string
    section_id: 
      type: integer
      notnull: true
  relations:
    Section: 
      foreignAlias: Pages
    SubPage:
      class: Page
      local: subpage
      foreign: id
      type: one

But, when I execute the build-all-reload command, the following error message is displayed:

SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'subpage' doesn't exist in table

I'm trying to implement a self-relation class.


I think you want to have what you have listed:

SubPage:
  class: Page
  local: subpage
  foreign: id
  type: one

but you need an id column (foreign: id) for the primary key of the Page table and a column called 'subpage' which contains the reference (local: subpage) to the child. So you may have Page with id = "100" containing a field called subpage which contains an id = "200" and that "200" is the actual key (id) of a different page.

UPDATE: From comment to modify original schema file:

Page:
  actAs:
    I18n:
      fields: [name,html,urlShortDesc]
  columns:
    name: string
    gender: 
      type: enum
      values: [html, photoGallery]
      default: html
    html: string
    urlShortDesc: string
    section_id: 
      type: integer
      notnull: true
    id: 
      type: integer
      notnull: true
    subpage: 
      type: integer
      notnull: false
  relations:
    Section: 
      foreignAlias: Pages
    SubPage:
      class: Page
      local: subpage
      foreign: id
      type: one

Please note that I am making some serious assumptions on your schema including:

  • you want id as your primary key and that you will take care of it being set (you may want autoincrement: true in the schema).
  • subpage is optional as a child relation
  • section_id is not your primary key
0

精彩评论

暂无评论...
验证码 换一张
取 消