first I have run this command
rails generate model FeedbackComment type:smallint reply:text
after then
rake db:migrate 
I am getting this error
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'
How can i create smallint through command in postgreSQL ?
Please hellp me
As I said,there is no smallint that supports Rails 3.You should be using integer datatype with limit of 2 bytes to make it as smallint.
For a list of available Rails 3 datatypes,see this SO Post.
This command will give you what you want
rails generate model FeedbackComment type:integer{2} reply:text
See this link for advanced Rails model generators.
Here is some more useful info
: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
                        The way of adding PostgreSQL smallint data type in Rails 6, 5, and 4 is still the same, an integer data type with limit 2.
class AddColumnNameToTableName < ActiveRecord::Migration[6.0]
  def change
    add_column :table_name, :column_name, :integer, limit: 2
  end
end
# => column_name smallint.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With