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 ...
随机推荐
- no-proxy 和proxy 的区别
Child <- many-to-one ->Parent class Child { private Parent paren ...
- IIS上部署Net.Core
部署: 1.安装vc_redist.x64vc_redist.x64 2.安装DotNetCore.1.0.0.RC2-WindowsHosting 3.安装DotNetCore.1.0.0-SDK. ...
- linux 安全狗
下载 ;安装; service safedog start 或者 sdstart;sdui
- 即使用ADO.NET,也要轻量级实体映射,比Dapper和Ormlite均快
不管出于什么原因,有时候框架人员摒弃了NH或EF,而使用原生数据库访问对象. 为了优美的编程,用上我写的轻量级映射扩展方法吧 目的:将SqlDataReader自动转换成T类型 代码如下: /// & ...
- [fiddler] 手机抓包
最近工作涉及到与原生app联调,需要抓取手机上的请求.借此机会研究了下fiddler,简直神器. 以下简单介绍通过fiddler进行手机抓包的方法,之后也会陆续更新fiddler的其他功能 设置fid ...
- 设计模式 “续”
观察者模式 再次申明,本文学习自 程杰 兄的 "大话设计模式" 根据书中的内容和自己的体会而来. 观察者模式也叫 发布.订阅模式,在这个模式里,一个目标物件管理所有依赖它的观察者物 ...
- <<< 入侵网站思路
思路: 以下是入侵网站常用方法: 1.上传漏洞 如果看到:选择你要上传的文件 [重新上传]或者出现“请登陆后使用”,80%就有漏洞了! 有时上传不一定会成功,这是因为Cookies不一样.我们就要用W ...
- maven的eclise配置
http://blog.csdn.net/guanning0109/article/details/26069277
- XML 架构 (XSD) 参考
https://msdn.microsoft.com/zh-cn/library/ms256235.aspx XML 架构示例 XML 架构元素 XML 数据类型引用 XML 架构正则表达式 XML ...
- sql 从一个库中取某个表的数据导入到另一个库中相同结构的表中
sql 2008 从一个库中把 某个表中的数据导入到另一个库中的具有相同结构的表中 use 库1 go insert into 库1.dbo.表1 select * from 库2.dbo.表1 ...