Rails 4:可用数据类型列表 [英] Rails 4: List of available datatypes
问题描述
在哪里可以找到可在 Ruby on Rails 4 中使用的数据类型列表?比如
Where can I find a list of data types that can be used in Ruby on Rails 4? Such as
文本
字符串
整数
浮动
日期
我一直在学习新的东西,我很想有一个我可以轻松参考的列表.
I keep learning about new ones and I'd love to have a list I could easily refer to.
推荐答案
以下是所有 Rails 4(ActiveRecord 迁移)数据类型:
Here are all the Rails 4 (ActiveRecord migration) datatypes:
:二进制
:boolean
:日期
:日期时间
:十进制
:float
:整数
:bigint
:primary_key
:references
:string
:text
:时间
:时间戳
来源:http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-add_column
这些与 Rails 3 相同.
如果您使用 PostgreSQL,您还可以利用这些:
If you use PostgreSQL, you can also take advantage of these:
:hstore
:json
:jsonb
:array
:cidr_address
:ip_address
:mac_address
如果您使用非 PostgreSQL 数据库运行您的应用,它们将存储为字符串.
They are stored as strings if you run your app with a not-PostgreSQL database.
编辑,2016 年 9 月 19 日:
有 a更多 Rails 4 中的 postgres 特定数据类型和 甚至更多.
There's a lot more postgres specific datatypes in Rails 4 and even more in Rails 5.
这篇关于Rails 4:可用数据类型列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!