Beginner Rails articles written by beginners for beginners
rails db:migrate:status
database: first_development
Status Migration ID Migration Name
--------------------------------------------------
up 20201115064445 Create members
Execute the command by specifying the list of numbers (year, month, day, day) in the file name.
rails db:migrate VERSION=20201115064445
You can use it when you realize that "Oh, there's a guy I forgot to write!"
rails db:migrate:rollback
python
#Command to create migration file
rails g migration rename_Column name before change_column_to_table name(Plural form)
#Contents of migration file
class Rename Column name before change ColumnTo Table name s< ActiveRecord::Migration[5.2]
def change
rename_column :Table name (plural), :Column name before change, :Column name after change
end
end
python
#Command to create migration file
rails g migration rename_Column name before change_column_to_table name(Plural form)
#Contents of migration file
class Rename Column name before change ColumnTo Table name< ActiveRecord::Migration[5.2]
def change
rename_column :Table name (plural), :Column name before change, :Column name after change
end
end
python
#Command to create migration file
rails generate migration add_index_table name_Column name
#Contents of migration file
class AddIndexTo table name< ActiveRecord::Migration
def change
add_index :table name,Column name
end
end
A handyman who speeds up the search when retrieving data from a particular column. For example, I want to search for a user by name! If there is no index in the name column of the Users table, check the name column of the User table one by one from the top and try to get the data of the corresponding user. If this confirms the data of tens of thousands of people from scratch, it will take time even for programming. Therefore, by putting an index in the name column of the Users table, you can sort the names in alphabetical order and make it easier to search.
Recommended Posts