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. [No00006C]文件名复制,归档小助手【自己写的小工具,希望能帮助大家】

    特别补充一句:软件可以一次性复制多个文件的文件名. Windows 中的复制文件名实在是有些不方便 ,需要点右键 "重命名"之后再点右键选择"复制"才可复制文件 ...

  2. C++的vector对象

    C++的vector使用 标签(空格分隔): C++ 标准库类型vector表示对象的集合,其中所有对象的类型都相同.集合中的每个对象都有一个与之对应的索引,索引用于访问对象,因为vector容纳着其 ...

  3. play with make

    1) the VPATH variable In make world, the VPATH variable guide you where to find the .c/.o file 2) th ...

  4. Swift学习(二):自定义扩展方法(Extensions)

    扩展就是向一个已有的类.结构体或枚举类型添加新功能(functionality) 扩展可以 添加计算型属性和计算静态属性 定义实例方法和类型方法 提供新的构造器 定义下标 定义和使用新的嵌套类型 使一 ...

  5. C#进阶系列——DDD领域驱动设计初探(二):仓储Repository(上)

    前言:上篇介绍了DDD设计Demo里面的聚合划分以及实体和聚合根的设计,这章继续来说说DDD里面最具争议的话题之一的仓储Repository,为什么Repository会有这么大的争议,博主认为主要原 ...

  6. 回文自动机(BZOJ2565)

    #include <cstdio> #include <cstring> #include <iostream> using namespace std; ][], ...

  7. pagerank

    http://jung.sourceforge.net/ https://github.com/louridas/pagerank/blob/aeb9b17ada1f925bb525961574f6d ...

  8. Android 线程池(转)

    new Thread的弊端及Java四种线程池的使用: 1.new Thread的弊端 ); } catch (InterruptedException e) { // TODO Auto-gener ...

  9. 解决:Microsoft Office Word已停止工作

    1/按组合键WIN+R打开运行对话框 2/在打开框中键入%USERPROFILE%\AppData\Roaming\Microsoft\Templates,单击“确定”按钮 3/在打开的窗口鼠标右键删 ...

  10. eclipse注释快捷键(含方法注释)

    整段注释: /*public boolean executeUpdate(String sql) { System.out.println(sql); boolean mark=false; try ...