[ rails ] add column to the model

add column to the model

convention : Add[column]To[model]

rails g migration AddBioToNameOfModel bio:text
create db/migrate/YYYYMMDDHHMMSS_add_bio_to_name_of_model.rb

 

db/migrate/YYYYMMDDHHMMSS_add_bio_to_name_of_model.rb

class AddBioToNameOfModel < ActiveRecord::Migration
def change
add_column :modeles, :bio, :text
end
end

run

rake db:migrate

 

data type

https://stackoverflow.com/questions/17918117/rails-4-list-of-available-datatypes

 

Manual add column to database

ALTER TABLE table_name
ADD column_name datatype;

ref : https://stackoverflow.com/questions/30528877/rails-4-add-new-column-or-field-in-model,

https://www.w3schools.com/sql/sql_alter.asp

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s