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,因为这个是用来做外键的,存储的是数据库的自增主键
migration integer limit option的更多相关文章
- POJ 1650 Integer Approximation
Integer Approximation Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5081 Accepted: ...
- 根据start和limit从已有的数据列表中获取从start开始的limit个数据
代码记录(需求:根据start和limit从已有的数据列表中获取从start开始的limit个数据) 已有的数据列表:这个数据列表是经过处理的,可能是在SQL查询时无法处理的如多条件排序,而排序条件需 ...
- 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 ...
- polymorphic-associations 多态关联实例 ruby on rails
这次做新项目的时候,把图片都放在了一个表里,其他表中不再存图片信息,通过多态关联建立表之间的关系. (1)新建picture表, component表不需要处理 class CreatePicture ...
- thinkphp 迁移数据库 -Phinx 简单说明文档
php think migrate migrate:create Create a new migration ///创建 migrate:rollback Rollback the last or ...
- HANA SQL
约束 注释 你可以给你的 SQL 语句添加注释来增加可读性和可维护性. SQL 语句中注释的分隔如下: l 双连字符“--”.所有在双连字符之后直到行尾的内容都被 SQL 解析器认为是注释. l ...
- redis学习教程之一基本命令
参阅redis中文的 互动教程(interactive tutorial)来学习的. 目录: 全局操作 get get incr 自增 del 删除 expire 定时 list 队列 set ...
- Rails下cloud datastore的使用
Rails下cloud datastore的使用 背景 部门有一个项目要用Ruby做 WebAPI,DB使用关系型数据库Cloud Sql和非关系型数据库Cloud Datastore . 还不了 ...
- change column to bigint
今天存储数据的时候报错,发现是3435065640超出了常规int的存储长度, RangeError (3435065640 is out of range for ActiveRecord::Typ ...
随机推荐
- Java的泛型反射
If the superclass is a parameterized type, the {@code Type} * object returned must accurately reflec ...
- Centos6安装Gitlab
安装参考 https://about.gitlab.com/downloads/ 可以从清华的镜像下载安装包, 注意区分自己用的是哪个发行版 https://mirror.tuna.tsinghua. ...
- nodejs express 静态文件的路径
当express 设置为静态文件服务器的时候.可以通过2种方式进行方位: 1,通过设置app.use('路径1','../a/b/image') express 路径的形式,如 src="路 ...
- void 0作用
undefine 是可以被赋值的. 但是void 操作符 通过 计算 void 后面的变量名后还是会返回一个undefined ,这样就保证了你的undefined即使被定义了,采用void 表达式, ...
- MATLAB常用字符串函数之二
1,lower和upper lower: 将包含的全部字母转换为小写. upper: 将包含的全部字母转化为大写. 实例一: >>str='Sophia is a good girl.'; ...
- 2016-2017-2 《Java程序设计》教学进程
2016-2017-2 <Java程序设计>教学进程 目录 考核方式 课前准备 教学进程 第00周学习任务和要求 第01周学习任务和要求 第02周学习任务和要求 第03周学习任务和要求 第 ...
- python基础-文件操作
一.文件操作 打开文件时,需要指定文件路径和以何等方式打开文件,打开后,即可获取该文件句柄,日后通过此文件句柄对该文件操作. 打开文件的模式有: r ,只读模式[默认模式,文件必须存在,不存在则抛出异 ...
- java高新技术-java5的静态导入与编译器语法设置
静态导入 import语句可以导入一个类或某个包中的所有类 import static 语句导入有一个类中的某个静态方法或所有静态方法 使用Math.random() 可以这样做 package co ...
- 项目中CKEditor修改宽度为自适应
项目中用到CKEditor,在config.js中直接定义config.width使得宽度无法自适应,尝试了好多次后发现了一种方法: 放弃在config.js中配置宽度 在页面检查元素,找到id为ck ...
- Java核心思想
回忆面向对象思想 面向对象,主页君也不敢对其多说什么,毕竟这是一个看似简单,但是其实蕴含很深层次理 论的东西,并不是看书就可以理解的,其实也是要在很多实际操作中学习,积累. ...