[英]How can I change the type of a property in Geddy
如何更改Geddy中現有財產的類型?
我相信我需要在定義模型文件中的屬性時更改設置的類型:
this.defineProperties({
title: {type: 'string', required: true},
description: {type: 'text'},
status: {type: 'boolean'}
});
我還認為我需要在遷移中更改表。 我正在使用http://geddyjs.org/guide#models此處記錄的'changeColumn'函數
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”選項(如您所見),但是沒有提供任何有用的信息。
我還懷疑我實際上需要更改表中的某些數據(以便它可以映射到新的數據類型),但是文檔尚不清楚如何執行此操作。
任何幫助表示贊賞。 謝謝。
不幸的是,SQLite不支持ALTER COLUMN( http://www.sqlite.org/lang_altertable.html )。 這只是SQLite適配器中的一個問題,它不會影響Postgres或MySQL。 還有一些解決方法,如下所述: 如何重命名SQLite數據庫表中的列? 您可以編寫執行這些步驟的遷移。 當您嘗試使用SQLite適配器執行此操作時,Geddy的ORM(現在在NPM上)的0.4.16版本現在包含友好的錯誤消息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.