DataMapper 将列迁移到新的数据类型
问题是我无法将列类型更改为“文本”
这是我看到的错误:
DarkBook:playground Justin$ rake migrate_up (in /Users/Justin/Dropbox/Business/datamapper/playground) ~ 开始迁移== 执行迁移 #1:create_person_table创建表 people
(id
SERIAL PRIMARY KEY, name
VARCHAR(2), age
INTEGER) ENGINE = InnoDB 字符集 utf8 整理 utf8_general_ci -> 0.0112s-> 0.0129s == 执行迁移#2:change_name_constraints rake 中止! 未初始化的常量 SQL::TableModifier::Text /Users/Justin/Dropbox/Business/datamapper/playground/rakefile.rb:61:in `block (3 level) in ' (通过使用 --trace 运行任务查看完整跟踪) 我用来测试 DataMapper 的 Rake 脚本: https://gist.github.com/818143 似乎 TableModifier 类中的change_column 方法没有将列更改语句正确转换为MySQL。其他看似相关的错误是,如果我尝试将列转换为更长长度的字符串,我会得到以下信息: DarkBook:playground Justin$ rake migrate_up(在 /Users/Justin/Dropbox/Business/datamapper/playground) ~ 开始迁移 == 执行迁移 #2:change_name_constraints
ALTER TABLE 人员
ALTER COLUMN 姓名
类型字符串
~ 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行“TYPE String”附近使用的正确语法(代码:1064,sql 状态:42000,查询:ALTER TABLE people
ALTER COLUMN name
TYPE String,uri:mysql://root:@127.0.0.1datamapper_test) rake 中止! 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行
/Users/Justin/Dropbox/Business/datamapper/playground/rakefile.rb:60:in `block (2 level) 的 'TYPE String' 附近使用的正确语法in ' (通过使用 --trace 运行任务查看完整跟踪)
根据我读过的有关 MySQL 的内容,“ALTER TABLE people
ALTER COLUMN name
TYPE String”不是有效的 MySQL 查询命令。 TYPE 不应该存在,并且 String 应该转换为 VARCHAR。
查看 Change_column 方法内部,我发现它只是我提供的类型的直接传递。这让我想也许我不应该直接调用change_column方法?
一旦我弄清楚了这一点并且我的工作进展顺利,我就会记录这些内容,因为我发现 DataMapper 的迁移 api 非常糟糕。
Issue is that I can't change a column type to 'Text'
This is the error I am seeing:
DarkBook:playground Justin$ rake migrate_up
(in /Users/Justin/Dropbox/Business/datamapper/playground)
~ Starting Migration
== Performing Up Migration #1: create_person_table
CREATE TABLE people
(id
SERIAL PRIMARY KEY, name
VARCHAR(2),
age
INTEGER) ENGINE = InnoDB CHARACTER SET utf8 COLLATE
utf8_general_ci
-> 0.0112s
-> 0.0129s
== Performing Up Migration #2: change_name_constraints
rake aborted!
uninitialized constant SQL::TableModifier::Text
/Users/Justin/Dropbox/Business/datamapper/playground/rakefile.rb:61:in
`block (3 levels) in '
(See full trace by running task with --trace)
Rake script I'm using to test DataMapper:
https://gist.github.com/818143
It seems as though the change_column method within the
TableModifier class isn't converting the column change statement to
MySQL correctly. Other seemingly related errors are that if I try to
convert a column to a String of longer length I get this:
DarkBook:playground Justin$ rake migrate_up
(in /Users/Justin/Dropbox/Business/datamapper/playground)
~ Starting Migration
== Performing Up Migration #2: change_name_constraints
ALTER TABLE people
ALTER COLUMN name
TYPE String
~ You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'TYPE String' at line 1 (code: 1064, sql state: 42000, query:
ALTER TABLE people
ALTER COLUMN name
TYPE String, uri:
mysql://root:@127.0.0.1datamapper_test)
rake aborted!
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'TYPE String' at line 1
/Users/Justin/Dropbox/Business/datamapper/playground/rakefile.rb:60:in `block (2 levels) in ' (See full trace by running task with --trace)
According to what I've read about MySQL, "ALTER TABLE people
ALTER
COLUMN name
TYPE String" is not a valid MySQL query command. TYPE
shouldn't be there and String should be converted to VARCHAR.
Looking inside the change_column method I see it's just a straight pass through of the type I'm providing. This is making me think perhaps I'm not supposed to be calling the change_column method directly?
Once I get this figured out and I'm well on my way, I'm documenting this stuff as figuring out DataMapper's migration api has been hellish.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
change_column
不是特别亮。当前的实现是:意味着您需要指定底层 sql 类型而不是 DataMapper 类型。也就是说:
我将更新文档以包含此内容。
change_column
isn't particularly bright. The current implementation is:Meaning you need to specify the underlying sql type rather than a DataMapper type. To wit:
I will update the documentation to include this.
这是我发现的解决方法:
https://gist.github.com/819792
This is a work around I found:
https://gist.github.com/819792