【发布时间】:2010-10-06 01:47:30
【问题描述】:
数据库:OS X 上的 MySql 5.1.47
Application.cfc 中的 ORM 设置:
this.ormEnabled = true; 这个.ormsettings = { autogenmap = 真, dbCreate = application.dbCreate, 自动管理会话 = 真, 数据源 = application.dsn, logSQL = 应用程序.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)";
}
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)
尝试创建外键关系时,数据库创建失败。请注意,news 中的字段是 varchar(255)。那个是从哪里来的?我试图在我能找到的每个地方都将它设置为整数,但它总是生成为 varchar。我认为这就是关系失败的原因,因为这两个字段是不同的数据类型。
我做错了什么?
【问题讨论】:
标签: orm coldfusion