This time, I will leave a memorandum on how to create a database table in Ruby on Rails6.
bin / ・ ・ ・ </ strong> is used in the Linux </ strong> development environment. (I don't need this character in the development environment on MAC {Unix}, but I think it's good to have it as knowledge.) Also, the table name should be capitalized, such as "Form".
command
$ bin/rails g model Smple_form title:string
$ bin/rails g model table name column name:Data type
or
$ bin/rails generate model Smple_form title:string
$ bin/rails generate model Dable name Column name:Data type
command
$ bin/rails g model Smple_form description:text title:string
$ bin/rails g model table name column name:Data type column name:Data type
or
$ bin/rails g generate Smple_form description:text title:string
$ bin/rails g generate table name column name:Data type column name:Data type
command
$ rails db:migrate
Sometimes I forget to migrate and get an error. Please be careful.
↓ means that multiple columns have been created.
20200926124610_create_Optional s.rb
class CreateGoals < ActiveRecord::Migration[6.0]
def change
create_table :goals do |t|
t.text :description
t.string :title
t.timestamps
end
end
end
Thank you for reading this far. That's all for creating the model and database. It was nice to be able to record multiple column settings. Please make use of it.
Also, there is a link on Twitter / Portfolio, so if you are interested, Please connect. I would be very happy to have friends who can share programming learning.
Recommended Posts