zoukankan      html  css  js  c++  java
  • migration integer limit option

    https://gist.github.com/stream7/1069589

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

    关于sequence 字段
    limit: 2 是两个字节,16 位,2 的 15 次方是 32767

    class CreateTableSubjections < ActiveRecord::Migration[5.0]
      def change
        create_table :table_subjections do |t| 
          t.belongs_to :subject, index: true
          t.belongs_to :video, index: true
          t.string :title, limit: 40
          t.string :sub_title, limit: 40
          t.string :description, limit: 500
          t.integer :status, limit: 1
          t.integer :sequence, limit: 2
    
          t.timestamps
        end 
      end 
    end

    对于多态关联的表

    class CreateSubjections < ActiveRecord::Migration[5.0]
      def change
        create_table :subjections do |t| 
          t.belongs_to :subject, index: true
          t.string :title, limit: 40
          t.string :sub_title, limit: 40
          t.string :description, limit: 500 
          t.string :subjectable_type, limit: 20
          t.integer :subjectable_id
          t.integer :status, limit: 1
          t.integer :sequence, limit: 2
    
          t.timestamps
        end 
    
        add_index :subjections, [:subjectable_type, :subjectable_id]
      end 
    end

    t.integer :subjectable_id 不需要设置limit,因为这个是用来做外键的,存储的是数据库的自增主键

  • 相关阅读:
    线性表之链式存储结构
    最大公约数:辗转相除法
    字符串系列之:逆序输出字符串
    链表有关的常见面试题
    从数组中找出最大的和最小的数
    C语言实现简单线程池
    线性表之顺序存储结构
    新学了姜葱豆腐
    渗透1
    MySQL注入中新Tips
  • 原文地址:https://www.cnblogs.com/iwangzheng/p/5881042.html
Copyright © 2011-2022 走看看