簡體   English   中英

Doctrine 1.2 / Symfony 1.4沒有產生正確的外鍵關系?

[英]Doctrine 1.2/Symfony 1.4 not generating proper foreign-key relationships?

我繼承了我必須維護的Symfony 1.4 / Doctrine 1.2應用程序。 我試圖對schema.yml文件進行一些更改並生成新模型和sql defns,但由於某種原因,我的外鍵關系沒有完全生成。

我認為我可能在schema.yml文件中遺漏了一些明顯的東西,但它並沒有突然出現在我面前:

我已將schema.yml文件編輯為一些基礎知識:

SCHEMA.YML:
connection: doctrine
options:
  type: innodb
  charset: utf8

MasterIndex:
  tableName: master_index
  columns:
    id:
      type: integer
      primary: true
      autoincrement: true
    last_name:
      type: string(255)
      notnull: true
    first_name:
      type: string(255)
      notnull: true

Poem:
  tableName: poem
  columns:
    id:
      type: integer
      primary: true
      autoincrement: true
    user_id: string(50)
    title: string(250)
    pen_name: string(250)
    contents: string()
    invoice_id: integer
  relations:
    Invoice:
      local: invoice_id
      foreign: id
      foreignAlias: poems
      foreignType: many
      type: one
    MasterIndex:
      local: user_id
      foreign: id
      foreignAlias: poems
      foreignType: one
      type: many

Invoice:
  tableName: invoice
  columns:
    id:
      type: integer
      primary: true
      autoincrement: true
    user_id:
      type: string(50)
      notnull: true
    amount:
      type: float()
      notnull: true

在運行symfony doctrine之后:clean doctrine:build-model和doctrine:build-sql,我得到以下schema.sql生成:

CREATE TABLE invoice (id BIGINT AUTO_INCREMENT, user_id VARCHAR(50) NOT NULL, amount FLOAT(18, 2) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 ENGINE = innodb;
CREATE TABLE master_index (id BIGINT AUTO_INCREMENT, last_name VARCHAR(255) NOT NULL, first_name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 ENGINE = innodb;
CREATE TABLE poem (id BIGINT AUTO_INCREMENT, user_id VARCHAR(50), title VARCHAR(250), pen_name VARCHAR(250), contents TEXT, invoice_id BIGINT, INDEX invoice_id_idx (invoice_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 ENGINE = innodb;
ALTER TABLE poem ADD CONSTRAINT poem_invoice_id_invoice_id FOREIGN KEY (invoice_id) REFERENCES invoice(id);

我希望poem表中有2個外鍵約束 - invoice_id到Invoice表,user_id到MasterIndex表,但只出現一個約束! 我在poem表中缺少我的外鍵約束到master_index表。

我忽略了一些明顯的東西嗎

外鍵必須與引用列的類型匹配:

user_id: type: string(50)應為user_id: type: integer

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM