smallint无法生成模型和表格栏3+ postgreSQL

Har*_*man 4 postgresql ruby-on-rails mode

首先我运行了这个命令

rails generate model FeedbackComment type:smallint reply:text
Run Code Online (Sandbox Code Playgroud)

然后

rake db:migrate 
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误

StandardError: An error has occurred, this and all later migrations canceled:

undefined method `smallint' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::TableDefinition:0x9d1a318>/var/www/blog/db/migrate/20140712064127_create_feedback_comments.rb:4:in `block in change'
Run Code Online (Sandbox Code Playgroud)

如何在postgreSQL中通过命令创建smallint?

请帮帮我

Pav*_*van 13

正如我所说,没有smallint支持Rails 3.你应该使用integer datatypelimit of 2 bytes来实现它smallint.

有关可用Rails 3数据类型的列表,请参阅此SO帖子.

此命令将为您提供所需的内容

rails generate model FeedbackComment type:integer{2} reply:text
Run Code Online (Sandbox Code Playgroud)

请参阅此链接以获取高级Rails模型生成器.

这是一些更有用的信息

:limit     Numeric Type  Column Size    Max value
1          tinyint       1 byte         127
2          smallint      2 bytes        32767
3          mediumint     3 bytes        8388607
nil, 4, 11 int(11)       4 bytes        2147483647
5..8       bigint        8 bytes        9223372036854775807
Run Code Online (Sandbox Code Playgroud)