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. sicily 中缀表达式转后缀表达式

    题目描述 将中缀表达式(infix expression)转换为后缀表达式(postfix expression).假设中缀表达式中的操作数均以单个英文字母表示,且其中只包含左括号'(',右括号‘)’ ...

  2. HTML5入门(CSS样式-------------------(CSS基础知识点----------------------------))

    CSS继承性+层叠性+盒子+浮动 一.CSS继承性 eg:                 <style>                               div{       ...

  3. jQuery如何在IE中更改网页标题

    标准上来说,要改变title值要操作document而不是title节点.在IE下不能通过操作title节点来改变document.title. 本来用原生的JavaScript很简单就解决了: do ...

  4. 20145315&20145307《信息安全系统设计基础》实验五

    20145315&20145307<信息安全系统设计基础>实验五 北京电子科技学院(BESTI) 实 验 报 告 课程:信息安全系统设计基础 班级:1453 1452 姓名:陈俊达 ...

  5. 玩蛇记--Python处理海量手机号码

    一.任务描述 上周,老板给我一个小任务:批量生成手机号码并去重.给了我一个Excel表,里面是中国移动各个地区的可用手机号码前7位(如下图),里面有十三张表,每个表里的电话号码前缀估计大概是八千个,需 ...

  6. 支持断线重连、永久watcher、递归操作并且能跨平台(.NET Core)的ZooKeeper异步客户端

    在公司内部的微服务架构中有使用到了"ZooKeeper",虽然官方有提供了.NET的SDK,但易用性非常的差,且搜遍github.nuget,没有发现一个可以跨平台且易用的组件,所 ...

  7. Windows phone应用开发[21]-图片性能优化

    在windows phone 中常在列表中会常包含比较丰富文字和图片混排数据信息. 针对列表数据中除了谈到listbox等控件自身数据虚拟化问题外.虽然wp硬件设备随着SDK 8.0 发布得到应用可使 ...

  8. MVC模式在UI里的应用

    In a similar way to other parts of a game, user interfaces usually go through several iterations unt ...

  9. matlab 将多个盒图放在一张图上

    1.boxplot 将多个盒图放在一张图上 x1 = normrnd(5,1,100,1)';x2 = normrnd(6,1,200,1)';X = [x1 x2];G = [zeros(size( ...

  10. Maven使用archetype迅速生成项目骨架

    archetype意思是"原型",相当于项目模板.archetype是maven的一个插件,相当于模板工具包. 一个十分重要的mvn指令:mvn 插件名:目标名maven自带三个内 ...