创建表方法:
- rails generate model Experts
- 在db/migrate/2019xxx_create_experts.rb 文件中,
class CreateExperts < ActiveRecord::Migration
def change
create_table 'experts' do |t|
t.string 'name'
t.string 'image',comment: '头像'
t.string 'university',comment: '毕业学校'
t.text 'introduction',comment: '简介'
t.string 'company',comment: '公司'
t.string 'title',comment: '头衔'
t.integer 'position',comment: '权重'
t.integer 'is_blocked',limit: 4,default:0,comment: '是否屏蔽;0:不屏弊;1:屏蔽'
t.integer 'class', default:1, comment: '专家分类.1:首席经济学家/经济;2.证券分析师/投资顾问委员会;3.自媒体大V'
t.timestamps null: false
end
end
end
执行 rake db:migrate
增加字段,两种方法:
4. rails g migration [名字] [字段名]:[类型], [字段名]:[类型]
5. rails generate migration add_class_to_experts 然后在文件中写
class AddClassToExperts < ActiveRecord::Migration
def change
add_column :experts, :class, :integer, default:1, comment: '专家分类.1:首席经济学家/经济;2.证券分析师/投资顾问委员会;3.自媒体大V'
end
end
rails generate migration add_password_digest_to_users