views:

56

answers:

3

In my Rails 3 app, I am creating a Book model which contains an ISBN column. This ISBN value will be a number 13 characters long. Which type should I use to create the ISBN column? Should I use an :integer or a :string? What is the maximum size of an integer in Rails?

rails g scaffold Book title:string isbn:integer
+1  A: 

The maximum size of the integer depends on the database being used. For MySQL it's 2147483648 (2^31 since it's an unsigned integer.) I would recommend you store the ISBN as a string (likely a CHAR(13) if possible.)

rjk
A: 

ISBN things like thisISBN 978-7-111-27687-6,so obviously string is a good choice

juliet
A: 

ISBN numbers also contain characters i.e hyphen(-) which obviously you cannot store in integer form. So I would recommend you to use string.

Rohit