[RUBY] A memorandum about table data types and commands (Rails)

Introduction

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

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

Commands used when creating tables and columns

When making tables and columns

$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

Delete table

$rails d model model name

Example of use

$ rails d model User

Command to add / remove columns to existing table

Add column

$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

Delete column

$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

Migration execution

Execute the db: migrate command to reflect it in the DB when it can be created, changed, or deleted.

$ rails db:migrate

Recommended Posts

A memorandum about table data types and commands (Rails)
Rails: A little summary about data types
About Java data types (especially primitive types) and literals
[Rails] I learned about database data type types!
(Ruby on Rails6) Creating data in a table
A note about the Rails and Vue process
About Java basic data types and reference type memory
Rails Tutorial Records and Memorandum # 0
Basic data types and reference types (Java)
Rails model and table naming conventions
About Java primitive types and reference types
Java basic data types and reference types
Consideration about Rails and Clean Architecture
[Rails] I learned about migration files! (Adding a column to the table)
[Rails] How to create a table, add a column, and change the column type
[Swift] A note about function and closure
[Creating] A memorandum about coding in Java
About Rails 6
Rails memorandum
How to make a unique combination of data in the rails intermediate table
Find out about Rails hidden_field (create a confirmation screen and check the behavior)
[Rails / ActiveRecord] About the difference between create and create!
A story about Apache Wicket and atomic design
About table changes and database resets after deployment
[Ruby on Rails] A memorandum of layout templates
[Rails tutorial] A memorandum of "Chapter 11 Account Activation"
Spring Boot + Spring Data JPA About multiple table joins
[Ruby] Setting values ​​and memorandum for the table
A memo about the types of Java O/R mappers and how to select them