adding more fields to a database

do I have to repeat this command to add all my fields: rails generate AddnameToUsers name:string, What other way can be used to add multiple filed

Posted about 4 years ago by Joseph Nnamdi
Posted about 4 years ago by Alex Yang

The AddXToY syntax is just a shortcut to create the contents of the migration file. You can easily customize the migration file as well. For example, you could run 'rails generate migration AddFieldsToUsers' and manually add more add_column statements as needed:

def change
add_column :users, :name, :string
add_column :users, :gender, :string
add_column :users, :address, :string

For more information, I recommend reading the Rails Guide on migrations, specifically section 2.1 on creating standalone migrations: