[英]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.