This time, we will describe the migrate file and add it.
First, edit the migrate file by referring to README.md.
README.md
##items table
| Column | Type | Options |
| ----------------- | ---------- | ----------------- |
| name | string | null: false |
| explanation | text | null: false |
| category_id | integer | null: false |
| state_id | integer | null: false |
| delivery_price_id | integer | null: false |
| prefectures_id | integer | null: false |
| delivery_time_id | integer | null: false |
| price | integer | null: false |
| user | references | foreign_key: true |
### Association
- belongs_to :user
- has_one :purchase
20210118070956_create_items.rb
class CreateItems < ActiveRecord::Migration[6.0]
def change
create_table :items do |t|
t.string :name, null: false
t.text :explanation, null: false
t.integer :category_id, null: false
t.integer :state_id, null: false
t.integer :delivery_price_id, null: false
t.integer :prefectures_id, null: false
t.integer :delivery_time_id, null: false
t.integer :price, null: false
t.references :user, foreign_key: true
t.timestamps null: false
end
end
end
After finishing the description, execute the following two points
% rails db:rollback
% rails db:migrate
Finally Check the table
This completes adding the table!
Recommended Posts