數據庫:在OS XColdFusion的ORM創建錯誤的數據類型
ORM設置在的Application.cfc的MySQL 5.1.47:
this.ormEnabled = TRUE; this.ormsettings = { autogenmap =真, dbCreate的= application.dbCreate, automanageSession =真, 數據源= 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)";
}
從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)
,當它試圖創建的外鍵關係的數據庫創建失敗。注意新聞中的字段是一個varchar(255)。那個是從哪裏來的?我試圖在每個我能找到的地方將它設置爲一個整數,但它總是以varchar的形式生成。我認爲這就是爲什麼關係失敗,因爲這兩個字段是不同的數據類型。
我在做什麼錯?
而這部作品,並允許出口的CForm完成,關係沒有出現在MySQL的存在。 ProductLineId仍然被創建爲varchar(255)。看起來應該是int – anopres 2010-10-07 01:05:51