[英]ruby on rails 2.0+ scaffolding
My question is how do you find the "type" for a database column whats the difference between text / string. 我的问题是如何找到数据库列的“类型”,文本/字符串之间的区别是什么。 Is there anyway I can find this out?
反正我能找到这个吗?
script/generate scaffold ModelName field1:type field2:type field3:type
or
script/generate scaffold Post title:string body:text category_id:integer
Here is the list for mysql database 这是mysql数据库的列表
:binary blob
:boolean tinyint(1)
:date date
:datetime datetime
:decimal decimal
:float float
:integer int(11)
:string varchar(255)
:text text
:time time
:timestamp datetime
To get types for a DB column in MYSQL run: 要获取MYSQL中数据库列的类型,请运行:
desc table_name
In the Rails Console, run Model.inspect to get types for the corresponding table attrs: 在Rails控制台中,运行Model.inspect以获取对应表attrs的类型:
Studio.inspect
=> "Studio(id: integer, name: string, subdomain: string, workdays_mask: integer, created_by: integer, created_at: datetime, updated_at: datetime, workhours: text, template_styles: text, contact_info: text)"
The underlying types really depend on the database itself (and the Rails db driver implementation), but for MySQL: 底层类型实际上取决于数据库本身(以及Rails db驱动程序的实现),但对于MySQL:
String: VARCHAR default to a length of 255 - the MySQL default - unless you provide a length/size(?) value.
字符串:VARCHAR的默认长度为255-MySQL的默认长度-除非您提供length / size(?)值。
Text: TEXT or LONGTEXT ( http://dev.mysql.com/doc/refman/5.0/en/blob.html )
文字:TEXT或LONGTEXT( http://dev.mysql.com/doc/refman/5.0/en/blob.html )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.