Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

varchar Migration question for Ruby on Rails

I have created a new table including a column "note". The default is varchar(255) I believe but I wish to have this column be a text area vs. a field and to allow more data. I imagine that I would make this change in ActiveRecord::Migration file but I am curious as to the format. Do I simply change the varchar(255) to varchar(1000) for example? (if so what is the format?

def self.up     create_table :notes do |t|       t.string :note :varchar(1000)     end 

Is that the right format? Furthermore, how do I get the entry field to be multiple rows. Sorry if this is easy stuff but I am new to programming and RoR. Thanks.

like image 487
bgadoci Avatar asked Nov 02 '09 19:11

bgadoci


2 Answers

The correct format would be

t.string :note, :limit => 1000

make sure you are using a version of MySQL(or whichever database) which supports varchars longer than 256 characters.

if you want to use a large text block it would be

t.text :note

See http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html for more information

like image 106
The Who Avatar answered Sep 22 '22 06:09

The Who


You can change the length with the limit option as so...

def self.up   change_column :notes, :note, :string, :limit => 1000 end 
like image 30
Ben Crouse Avatar answered Sep 23 '22 06:09

Ben Crouse