A migration file is a file that describes the changes you make to the database.
command
#Modeling
$rails g model model name
#Migration file creation command
$rails g migration class name
The migration file is created when the model is created. It is also possible to specify the class name and create the migration file alone. It should be easy to understand that the class name is created by "action + table name"! This will create a file called /db/migrate/timestamp_classname.rb. Here are the changes to the schema!
command
$rails g model model name column name: data type
Specify the content to be described in the migration file when creating the model in "Column name: Data type".
The data types that can be specified are as follows.
command
#Executing the migration file
$ rails db:migrate
When this command is executed, the contents of the migration file will be reflected in the DB.
command
#Roll back the migration file
$ rails db:rollback
Roll back the executed migration file.
command
#Check the executed migration file
$ rake db:migrate:status
You can check the contents of the migration file executed by this command.
Recommended Posts