Let us say I have a initial migration which is created during the model generation
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :email
t.timestamps null: false
end
end
end
and sometimes later I want to add a field password in this migration like
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :email
t.string :password_digest
t.timestamps null: false
end
end
end
without creating a migration file rails generate migration add_password_digest_to_users password_digest: string
can I add t.string :password_digest
field to the initial file and run rake db:migrate
command.
Why do we need to create a migration file to add this, instead of just adding t.string :password_digest
and run bundle exec rake:db migrate
Isn't it overwhelming to create a 20 migrations, when we required to add 20 fields to the initial migration for a single model.
Aucun commentaire:
Enregistrer un commentaire