ActiveRecord 数据类型的文档页面在哪里? [英] Where is the documentation page for ActiveRecord data types?
问题描述
我找不到包含所有数据类型列表的活动记录文档页面.
I can't find the active record documenation page that has a list of all the data types.
有人可以帮我吗?
推荐答案
如果您在谈论迁移的类型,例如字符串、整数、日期时间等,然后你想要 ActiveRecord::ConnectionAdapters::TableDefinition,column 方法.(Rails 5 另见连接.add_column.)
If you're talking about the types for migrations, e.g. string, integer, datetime, etc, then you want ActiveRecord::ConnectionAdapters::TableDefinition, the column method. (Rails 5 edit: see also connection.add_column.)
截至本次更新,标准类型为:
As of this update, the standard types are:
:primary_key
:string
:text
:整数
:bigint
:float
:十进制
:数字
:日期时间
:时间
:日期
:二进制
:boolean
:decimal
的实现因每个数据库而异,所以我会尽可能避免它.您可以使用不在此列表中的类型,只要它受您的数据库支持(例如,MySQL 中的 :polygon
),但这与数据库无关,也应避免使用.
The implementation of :decimal
is different with each database, so I'd avoid it if possible. You may use a type not in this list as long as it is supported by your database (for example, :polygon
in MySQL), but this will not be database agnostic and should also be avoided.
这篇关于ActiveRecord 数据类型的文档页面在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!