Rails models 中 Schema Information 含义

aini · June 15, 2018 · Last by aini replied at June 15, 2018 · 1155 hits
# == Schema Information 
# 
# Table name: users
#
#  id              :integer          not null, primary key
#  name         :string(255)
#  address            :string(255)
#  tel         :string(255)
#  gender       :string(255)
#  created_at      :datetime         not null
#  updated_at      :datetime         not null

以上请教各位前辈,这种跟 mongoDB 的区别是什么?有什么好处?都加 # 注释了他是怎么运行到的?

这个只是注释而已,给人看的,你删了也没有影响的

Reply to kikyous

那意思是 这一段代码 是没有任何意义的,除了让人看着理解之外。

但是如果按你的意思 在这个 models 中没有声明任何字段,那么他在数据库中是怎么生成的跟注释中相同的字段的呢? 所以我觉得段代码还是运行到了的。

https://github.com/ctran/annotate_models

和你想的相反,那个是根据数据库字段生成的,就是给人看的,数据库的字段是 migration 生成的

Reply to IChou

学习了!第一次接触到数据库用的不是 MongoDB 的项目,所以有些不清楚的地方。项目数据库用 MySQL 是为了方便管理吗?

Reply to aini

大多数情况下,并不为啥,只是一个选择或喜好

只有到了具体的场景里面再去讨论 MongoDB or Mysql 才是有意义的

Reply to IChou

感谢

You need to Sign in before reply, if you don't have an account, please Sign up first.