15

Ruby on Rails では、移行の次のコードにより、tinyint(4)MySQLに型の列が作成されます。

create_table :great_table do |t|
    t.integer :step_position, :limit => 1 #tinyint
end

tinyint(2)タイプまたはタイプの列を作成するにはどうすればよいtinyint(3)ですか?

4

4 に答える 4

8

gem のソース コードで確認できることによると、次のことはできません。

     # File activerecord/lib/active_record/connection_adapters/mysql_adapter.rb, line   540  
     540:       def type_to_sql(type, limit = nil, precision = nil, scale = nil)
     541:         return super unless type.to_s == 'integer'
     542: 
     543:         case limit
     544:         when 1; 'tinyint'
     545:         when 2; 'smallint'
     546:         when 3; 'mediumint'
     547:         when nil, 4, 11; 'int(11)'  # compatibility with MySQL default
     548:         when 5..8; 'bigint'
     549:         else raise(ActiveRecordError, "No integer type has byte size #{limit}")
     550:         end
     551:       end

type_to_sql

于 2014-01-30T02:31:22.320 に答える