When creating a table, what was the data type in this case? What was the command? I decided to summarize it because there are times when I re-examine it.
| Data type | type | 
|---|---|
| integer | Numerical value (integer) | 
| decimal | Numerical value (highly accurate decimal number) | 
| float | Numerical value (floating point number) | 
| string | Character (short string) | 
| text | Character (long string | 
| date | date | 
| datetime | Date and time | 
| time | Times of Day | 
| timestamp | Time stamp | 
| binary | binary | 
| boolean | Authenticity | 
$rails g model model name column name:Data type
** Usage example **: When you want to create a user model and columns for name and self-introduction
$ rails g model User name:string introduction:text
$rails d model model name
Example of use
$ rails d model User
$rails g migration Add Column name To Table name Column name:Model name
** Usage example **: When you want to add a title column to the User table
$ rails g migration AddTitleToUsers title:string
$rails g migration Remove Column name From table name Column name:Model name
** Usage example **: When you want to delete the title column in the User table
$ rails g migration RemoveTitleFromUsers title:string
Execute the db: migrate command to reflect it in the DB when it can be created, changed, or deleted.
$ rails db:migrate
        Recommended Posts