zoukankan      html  css  js  c++  java
  • change column to bigint

    今天存储数据的时候报错,发现是3435065640超出了常规int的存储长度,

    RangeError (3435065640 is out of range for ActiveRecord::Type::Integer with limit 4)

    $ bundle exec rails db -p
    mysql> desc recommended_videos;
    +-------------------------+--------------+------+-----+---------+----------------+
    | Field                   | Type         | Null | Key | Default | Extra          |
    +-------------------------+--------------+------+-----+---------+----------------+
    | id                      | int(11)      | NO   | PRI | NULL    | auto_increment |
    | video_id                | varchar(255) | YES  |     |         |                |
    | res_desc                | text         | YES  |     | NULL    |                |
    | state                   | int(11)      | YES  |     | 0       |                |
    | created_at              | datetime     | YES  |     | NULL    |                |           |
    +-------------------------+--------------+------+-----+---------+----------------+

      

    http://dev.mysql.com/doc/refman/5.7/en/integer-types.html

    12.2.1 Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT

    MySQL supports the SQL standard integer types INTEGER (or INT) and SMALLINT. As an extension to the standard, MySQL also supports the integer types TINYINTMEDIUMINT, and BIGINT. The following table shows the required storage and range for each integer type.

    TypeStorageMinimum ValueMaximum Value
     (Bytes)(Signed/Unsigned)(Signed/Unsigned)
    TINYINT 1 -128 127
        0 255
    SMALLINT 2 -32768 32767
        0 65535
    MEDIUMINT 3 -8388608 8388607
        0 16777215
    INT 4 -2147483648 2147483647
        0 4294967295
    BIGINT 8 -9223372036854775808 9223372036854775807
        0 18446744073709551615
     
    int的存储上限是2147483647,
    所以change_column
    class ChangeTotalVvTypeToRecommendedVideos < ActiveRecord::Migration
      def change
        change_column :recommended_videos, :total_vv, :integer, :limit => 8
      end 
    end
    mysql> desc recommended_videos;
    +-------------------------+--------------+------+-----+---------+----------------+
    | Field                   | Type         | Null | Key | Default | Extra          |
    +-------------------------+--------------+------+-----+---------+----------------+
    | id                      | int(11)      | NO   | PRI | NULL    | auto_increment |
    | state                   | int(11)      | YES  |     | 0       |                |
    | sequence                | int(11)      | YES  |     | 1       |                |
    | created_at              | datetime     | YES  |     | NULL    |                |
    | updated_at              | datetime     | YES  |     | NULL    |                |
    | total_vv                | bigint(20)   | YES  |     | NULL    |                |
    +-------------------------+--------------+------+-----+---------+----------------+
  • 相关阅读:
    观察是快速成长的一个牛逼技能
    linux下使用lftp的小结(转)
    关于升级cocos2d-x网络库来支持ipv6、https,以及socket怎么支持ipv6
    cocos2dx支持arm64
    android studio 命令行编译cocos 3.15.1 安卓工程
    认识Android.mk和Application.mk
    mac os x下Android Studio3.0 配置本地 Gradle
    图片转成base64编码
    集成pbc
    6、SpringMVC:结果跳转方式 和 数据提交时的处理
  • 原文地址:https://www.cnblogs.com/iwangzheng/p/5524026.html
Copyright © 2011-2022 走看看