生产模式:什么是“最佳方式”\“最常用的方法”来更改和添加数据库中的数据?

时间:2022-04-17 00:13:02

I am using Ruby on Rails v3.0.9 and I have a web application running in production mode. I would like to change and add some data in the database (also, I would like to make that these data changes take effect in development mode - that is, for example, that the added data should be present also in development mode when I am running and developing my application on my local machine)...

我正在使用Ruby on Rails v3.0.9,我有一个在生产模式下运行的web应用程序。我想改变和添加一些数据在数据库中(同时,我愿在发展模式——这些数据更改生效,例如,添加数据时应该现在也在开发模式下运行和发展我的应用程序在本地机器上)……

... what is "the best way"\"the most commonly used approach" to do that? I mean, for example, should I create a migration file with in some User.create(:name => '...', :surname => '...', ...) statements and run those or there are other ways to accomplish what I would like to do?

…什么是“最好的方法”\“最常用的方法”来做到这一点?我的意思是,例如,我应该在某个用户中创建一个迁移文件。创建(:name = > '…”:姓= > '…或者有其他方法来完成我想做的事情?

Note: I do not need to populate the database with initial data (I already made that in the seed.rb file). I just need to update and add database table rows.

注意:我不需要用初始数据填充数据库(我已经在seed中这样做了)。rb文件)。我只需要更新和添加数据库表行。

2 个解决方案

#1


2  

seed.rb should be use only for initial set of values.

种子。rb应该只用于初始值集。

rake task should be use only when you want to update data any existing columns.

rake任务应该只在您想要更新任何现有列的数据时使用。

migration should be use when you need to change the schema of the table.

当需要更改表的模式时,应该使用迁移。

#2


0  

You should use the file db/seed.rb to accomplish this task

您应该使用文件db/seed。rb完成这项任务。

Here is an example on how to use it: http://asciicasts.com/episodes/179-seed-data

这里有一个如何使用它的示例:http://asciicasts.com/episode des/179种子数据

#1


2  

seed.rb should be use only for initial set of values.

种子。rb应该只用于初始值集。

rake task should be use only when you want to update data any existing columns.

rake任务应该只在您想要更新任何现有列的数据时使用。

migration should be use when you need to change the schema of the table.

当需要更改表的模式时,应该使用迁移。

#2


0  

You should use the file db/seed.rb to accomplish this task

您应该使用文件db/seed。rb完成这项任务。

Here is an example on how to use it: http://asciicasts.com/episodes/179-seed-data

这里有一个如何使用它的示例:http://asciicasts.com/episode des/179种子数据