0

私は維持しなければならない Symfony 1.4/Doctrine 1.2 アプリケーションを継承しました。schema.yml ファイルに変更を加えて、そこから新しいモデルと SQL 定義を生成しようとしていますが、何らかの理由で、外部キーの関係が完全に生成されていません。

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);

私は詩テーブルに 2 つの外部キー制約を期待しています - Invoice テーブルへの invoice_id と MasterIndex テーブルへの user_id ですが、1 つの制約しか表示されません! master_index テーブルへの詩テーブルの外部キー制約がありません。

私は明らかな何かを見落としていますか?

4

1 に答える 1

2

外部キーは、参照される列の型と一致する必要があります。

user_id: type: string(50)する必要がありますuser_id: type: integer

于 2012-12-21T12:17:42.367 に答える