Create a new table

suggest change

To create a new users table with the columns name and salary, run the command:

rails generate migration CreateUsers name:string salary:decimal

This will generate the following migration:

class CreateUsers < ActiveRecord::Migration[5.0]
  def change
    create_table :users do |t|
      t.string :name
      t.decimal :salary  
    end
  end
end

When the migration name has the form CreateXXX, followed by columns and types, the generator creates the table XXX with those columns. XXX is pluralized the usual Rails way: CreateUsers creates users.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents