2012-12-20 3 views
0

필자가 유지 관리해야하는 Symfony 1.4/Doctrine 1.2 애플리케이션을 상속 받았습니다. schema.yml 파일을 약간 변경하고 새 모델과 SQL defns를 생성하려고합니다. 그러나 어떤 이유로 외부 키 관계가 완전히 생성되지 않습니다.Doctrine 1.2/Symfony 1.4는 적절한 외래 키 관계를 생성하지 않습니까?

은 내가 가능성이 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 
: 깨끗한 교리 : 교리 모델을 구축 : 구축-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); 

내가이 외래 키 constrai을 기대하고 있습니다 poem 테이블의 nt - Invoice 테이블의 invoice_id와 MasterIndex 테이블의 user_id. 단 하나의 제한이 나타납니다! poem 테이블의 외래 키 제약 조건이 master_index 테이블에 없습니다.

나는 뭔가 뚜렷한 것을 간과하고 있습니까?

user_id: type: string(50)user_id: type: integer해야한다 :

+0

'user_id : type : string (50)'은'user_id : type : integer'이어야합니다. 외래 키는 참조 된 열의 유형과 일치해야합니다. – 1ed

+0

@ 1ed 나는 그것을 보지 못했다고 생각할 수 없다. 또한 foreignType과 Type이 섞여있는 것을 발견했습니다 (즉, 형식은 하나이어야하고 manyType이 많아야 함). 예상대로 작동합니다. - thx! –

답변

2

외래 키는 참조 열의 유형과 일치해야합니다.

관련 문제