This is a draft cheat sheet. It is a work in progress and is not finished yet.
Migration Commands
|
Update the database |
|
Undo the previous migration |
bin/rails db:migrate:redo
|
First rollback, then migrate |
Data Types
|
really big number |
|
alternate values |
|
true or false values |
|
a number |
|
|
Naming Conventions
CreateXXX col:type col:type
|
Creates a table named XXX with provided columns |
|
Adds column XXX to table YYY |
RemoveXXXFromYYY col:type
|
Removes column XXX from table YYY |
Create Table
The create_table
method creates a new table.
Available Options:
- primary_key: :key
: Customizes the primary key.
- force: true
: Drop the table if it already exists. Warning: This will result in unwanted data loss, if the existing table is populated.
- if_not_exists: true
: If you try to create a table with duplicate name, Rails will throw an error. This option lets you return silently without raising an error, if the table already exists.
- options
: Provide database-specific options.
- temporary: true
: Create a temporary table that will only exist during the current connection to the database.
- id: false
: Do not generate a primary key at all. Useful when creating join tables. However, as we'll see, better solutions exist for this, such as create_join_table
method. |
|