views:

103

answers:

3

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
A: 

The underlying types really depend on the database itself (and the Rails db driver implementation), but for MySQL:

String: VARCHAR default to a length of 255 - the MySQL default - unless you provide a length/size(?) value.

Text: TEXT or LONGTEXT (http://dev.mysql.com/doc/refman/5.0/en/blob.html)

Toby Hede
+1  A: 

Here is the list for mysql database

: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
Dinesh Atoliya
what about the auto incremented primary key I put id:integer and it show up editable?
ThomasReggi
NVM if you put a number in the field it still skips it to the db entry number. I should just remove the field in the edit view right?
ThomasReggi
+1  A: 

To get types for a DB column in MYSQL run:

desc table_name

In the Rails Console, run Model.inspect to get types for the corresponding table 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)"
nicholasklick
I want a way to find this out before I generate the scaffold. Is there a way?
ThomasReggi