2014-01-21 36 views
0

如何更改Geddy中的房產類型?如何更改Geddy中的房產類型

我相信我需要在模型文件中定義的屬性時改變類型集:

this.defineProperties({ 
    title: {type: 'string', required: true}, 
    description: {type: 'text'}, 
    status: {type: 'boolean'} 
}); 

我也覺得我需要改變的表中遷移。我使用「changeColumn」功能記錄在這裏http://geddyjs.org/guide#models

var StatusToBoolean = function() { 
    this.up = function (next) { 
    this.changeColumn("step", 'status', 'boolean', function (err, data) { 
     if (err) { throw err; } 
     next(); 
    }); 
    }; 

    this.down = function (next) { 
    this.changeColumn('step', 'status', 'string', function (err, data) { 
     if (err) { throw err; } 
     next(); 
    }); 
    }; 
}; 

exports.StatusToBoolean = StatusToBoolean; 

然而,當我運行這個遷移我收到了「SQLITE_ERROR:近‘ALTER’」錯誤:

Hindenburg:to_do Tom$ geddy jake db:migrate --trace 
Running migrations for development environment... 
Running status_to_boolean (up) 
jake aborted. 
Error: SQLITE_ERROR: near "ALTER": syntax error 
Hindenburg:to_do Tom$ 

這讓我認爲我做錯了什麼。我嘗試了'--trace'選項(正如你所看到的),但是這並沒有提供任何有用的信息。

我還懷疑我需要實際更改表中的某些數據(以便它可以映射到新的數據類型),但文檔尚不清楚如何執行此操作。

任何幫助表示讚賞。謝謝。

回答

1

不幸的是,SQLite不支持ALTER COLUMN(http://www.sqlite.org/lang_altertable.html)。這只是SQLite適配器中的一個問題,並不會影響Postgres或MySQL。也有解決方法,如下所述:How do I rename a column in a SQLite database table?您可以編寫執行這些步驟的遷移。 Geddy的ORM版本0.4.16(現在在NPM上)現在包含一個友好的錯誤消息,當您嘗試使用SQLite適配器執行此操作時。

+0

確實,這似乎是問題所在。看起來我應該能夠通過以某種方式將該列中的所有數據從當前值修改爲'true'或'false'或Geddy粘貼到創建爲「布爾值」的列中的所有數據來解決問題。 –