Database: MySql 5.1.47 on OS X
ORM Settings in Application.cfc:
this.ormEnabled = true; this.ormsettings = { autogenmap = true, dbCreate = application.dbCreate, automanageSession = true, datasource = application.dsn, logSQL = application.logSQL, sqlScript = application.sqlScript };
News.cfc
/**
* These are the news items
* @persistent true
* @accessors true
* @output false
* @entityname "News"
* @table news
*/
component
{
property name="NewsId" type="string" fieldtype="id" ormtype="integer" generator="native" generated="insert";
property name="Teaser" type="string" sqltype="varchar(200)";
property name="Story" type="string" sqltype="varchar(500)";
property name="ProductLineId" type="numeric" sqltype="int" ormtype="int" fieldtype="many-to-one" cfc="ProductLine" fkcolumn="ProductLineId" foreignkeyname="fk_productline_news";
}
ProductLine.cfc
/**
* @persistent true
* @accessors true
* @output false
* @table productline
*/
component
{
property name="ProductLineId" sqltype="int" fieldtype="id" ;
property name="Label" type="string" sqltype="varchar(50)";
}
Debug output from ORMReload()
[localhost]:10/05 21:32:00 [jrpp-70] HIBERNATE DEBUG -
[localhost]: create table news (
[localhost]: NewsId integer not null auto_increment,
[localhost]: Teaser varchar(200),
[localhost]: Story varchar(500),
[localhost]: **ProductLineId varchar(255)**,
[localhost]: primary key (NewsId)
[localhost]: )
[localhost]:10/05 21:32:00 [jrpp-70] HIBERNATE DEBUG -
[localhost]: create table productline (
[localhost]: ProductLineId int not null,
[localhost]: Label varchar(50),
[localhost]: primary key (ProductLineId)
[localhost]: )
[localhost]:10/05 21:32:01 [jrpp-70] HIBERNATE DEBUG -
[localhost]: alter table news
[localhost]: add index fk_productline_news (ProductLineId),
[localhost]: add constraint fk_productline_news
[localhost]: foreign key (ProductLineId)
[localhost]: references productline (ProductLineId)
The db creation fails when it attempts to create the foreign key relationship. Notice that the field in news is a varchar(255). Where did that come from? I tried to set it up as an integer in every place I could find but it always gets generated as a varchar. I think that is why the relationship fails since the two fields are different data types.
What am I doing wrong?