我继承了我必须维护的 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 学说:清洁学说:构建模型和学说:构建 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_id 到 Invoice 表,user_id 到 MasterIndex 表,但只出现一个约束!我在 master_index 表的诗歌表中缺少我的外键约束。
我是否忽略了一些明显的东西?