Reputation: 24481
I've inherited a Symfony 1.4/Doctrine 1.2 application that I have to maintain. I am trying to make some changes to the schema.yml file and generate new models and sql defns from it, but for some reason, my foreign key relationships are not being generated completely.
I presume that I am likely missing something obvious in the schema.yml file, but it isn't popping out at me:
I've edited the schema.yml file down to some basics:
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
After running a symfony doctrine:clean doctrine:build-model and doctrine:build-sql, I get the following schema.sql generated:
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);
I'm expecting 2 foreign key constraint in the poem table - invoice_id to the Invoice table and user_id to the MasterIndex table, but only one contraint appears! I am missing my foreign key constraint in the poem table to the master_index table.
Am I overlooking something obvious?
Upvotes: 0
Views: 1040
Reputation: 3668
Foreign keys must match the type of the referenced column:
user_id: type: string(50)
should be user_id: type: integer
.
Upvotes: 2