Rails 迁移常规命名
在 Rails 中进行迁移时,我知道如何使用“Rails 生成模型”命令创建模型。我的问题是,如果我想在模型中再添加一列,是否一定需要我提供一个如下描述性的新迁移名称?
例如:
1)我最初有一个名为“Employee”的模型,其中有一列名为“name”。
2)然后,我需要做的是添加一个名为“职业”的新列。 所以,我要做的是,我需要生成一个新的迁移,如下所示:
rails生成迁移add_occupation_to_employee职业:字符串
我只是遵循我从书中读到的描述性命名,但我不知道如何正确命名它。
我的问题是:是否有任何经验法则适用于“add_ocupation_to_employee”的命名?
when doing migration in rails, I know how to create a model using 'Rails generate model' command. My question here is if I would want to add one more column to the model, does it necessarily need me to give a new migration name as descriptive as below?
For example:
1) I originally have a model named 'Employee' with one column named 'name'.
2) Then, what I need to do is to add a new column named 'occupation'.
So, what I do is I need to generate a new migration as follows:
rails generate migration add_occupation_to_employee occupation:string
I just follow the descriptive naming on which I read from a book, but I got no idea how to name it properly.
My question is: Is there any rule of thumb applying to the naming of 'add_occupation_to_employee'?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Ruby on Rails 旨在强调约定优于配置。
因此,从“add_ocupation_to_employee”开始,Rails 自动将员工作为表,将职业作为列。
Ruby on Rails is intended to emphasize Convention over Configuration.
So from 'add_occupation_to_employee', Rails automatically takes employee as table and occupation as column.
没有经验法则,只需将您的迁移命名为像您所做的那样有意义的名称即可。例如:
等等。
There is no rule of thumb just name your migration something meaningful like the way you did. For example:
and so on.