Model is database data and ruby model class.
- Create simple model without any data type
- Create model with type
- Delete model
rails g model item
To do this, 4 files are generated.
Create model with sub directory
rails g model Products::Lucky
create app/models/products.rb, app/models/products/lucky.rb
rails generate model Country name population:integer
The definition is in migration file
class CreateCountries < ActiveRecord::Migration def change create_table :countries do |t| t.string :name t.integer :population t.timestamps end end end
timestamps field exists by default
ActiveRecord wraps each database type. Actually some database doesn't have a type, other database has. In this case, it does something to cover.
Same as controller
rails destroy model item
item is model name
All files are deleted which is relevant to
Migration is to change schema. All migration files are under db/migrate.
These files are executed according to timestamp.
Be careful to handle schema change.
Use rake command
Rollback one migration
Only one step
Do create, drop, migrate at the same time
Maybe switch back to the initial state.