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,因为这个是用来做外键的,存储的是数据库的自增主键

migration integer limit option的更多相关文章

  1. POJ 1650 Integer Approximation

    Integer Approximation Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5081   Accepted:  ...

  2. 根据start和limit从已有的数据列表中获取从start开始的limit个数据

    代码记录(需求:根据start和limit从已有的数据列表中获取从start开始的limit个数据) 已有的数据列表:这个数据列表是经过处理的,可能是在SQL查询时无法处理的如多条件排序,而排序条件需 ...

  3. 1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit

    Given an array of integers nums and an integer limit, return the size of the longest continuous suba ...

  4. polymorphic-associations 多态关联实例 ruby on rails

    这次做新项目的时候,把图片都放在了一个表里,其他表中不再存图片信息,通过多态关联建立表之间的关系. (1)新建picture表, component表不需要处理 class CreatePicture ...

  5. thinkphp 迁移数据库 -Phinx 简单说明文档

    php think migrate migrate:create Create a new migration ///创建 migrate:rollback Rollback the last or ...

  6. HANA SQL

    约束 注释 你可以给你的 SQL 语句添加注释来增加可读性和可维护性. SQL 语句中注释的分隔如下: l  双连字符“--”.所有在双连字符之后直到行尾的内容都被 SQL 解析器认为是注释. l  ...

  7. redis学习教程之一基本命令

    参阅redis中文的 互动教程(interactive tutorial)来学习的. 目录: 全局操作 get  get incr  自增 del 删除 expire 定时 list  队列 set ...

  8. Rails下cloud datastore的使用

      Rails下cloud datastore的使用 背景 部门有一个项目要用Ruby做 WebAPI,DB使用关系型数据库Cloud Sql和非关系型数据库Cloud Datastore . 还不了 ...

  9. change column to bigint

    今天存储数据的时候报错,发现是3435065640超出了常规int的存储长度, RangeError (3435065640 is out of range for ActiveRecord::Typ ...

随机推荐

  1. weka

    第一次接触weka这个东西,貌似是数据挖掘用的比较多.接下来一个月里,希望能够对weka有更深一步的了解,并用博客记录下学习weka用法.原理.数据预处理的过程,与君分享,期待!

  2. 第11章 Java异常与异常处理

    1.Java异常简介 1.什么是异常异常出现的时候代码会无法正常运行下去,会产生各种问题2.捕捉异常的作用提早发现异常,方便查找问题,并给出解决方法3.Java中的异常1.Java中所有不正常的类都是 ...

  3. 细说 C# 中的 IEnumerable和IEnumerator接口

    我们先思考几个问题: 为什么在foreach中不能修改item的值? 要实现foreach需要满足什么条件? 为什么Linq to Object中要返回IEnumerable? 接下来,先开始我们的正 ...

  4. git放弃本地修改 强制更新

    git fetch --all git reset --hard origin/mastergit fetch 只是下载远程的库的内容,不做任何的合并 git reset 把HEAD指向刚刚下载的最新 ...

  5. SQL/LINQ/Lamda 写法[转发]

    SQL LINQ Lambda SELECT * FROM HumanResources.Employee from e in Employees select e Employees   .Sele ...

  6. HBASE 安装法

    http://www.cnblogs.com/nexiyi/p/hbase_intro_94.html

  7. 各国货币M2增长对比

    自2006至2016年的10年间, 卢布M2增长了3.8倍, 人民币M2增长了3.4倍, 美元M2增长1倍, 欧元/英镑M2增长0.8倍, 日元M2增长0.5倍

  8. Nginx负载均衡实践之一:基本实现

    由于现在的网站架构越来越大,基于互联网的用户也是日渐增长,所以传统的单机版服务器已经渐渐不能适应时代发展的需要.最近在和其他企业接触的过程中,发现对于互联网的经验尤为看重,所谓的互联网经验,其实就是指 ...

  9. 如何重新划分linux分区大小

    1.下载脚本文件,将脚本文件内容复制 chmod +x resize.sh sudo ./resize.sh 输入上面命令后会看到下面的结果 root@odroid:~# sudo ./resize. ...

  10. PageHelper简单实用

    mybatis-config.xml配置如下: <!-- 分页插件 --> <plugins> <plugin interceptor="com.github. ...