我想向 p 表里的加入一条数据,使用下面这条语句 ruby script/generate migration add_data_to_p 可以吗? 还有请问下是在哪个路径下执行,我在工程名路径下执行提示说 no such file or directory。谢谢。
#1 楼 @nightire 生成一堆别的东西,不对啊 create create app/controllers create app/helpers create app/models create app/views/layouts create config/environments create config/initializers create config/locales create db create doc create lib create lib/tasks create log create public/images create public/javascripts create public/stylesheets create script/performance create test/fixtures create test/functional create test/integration create test/performance create test/unit create vendor create vendor/plugins create tmp/sessions create tmp/sockets create tmp/cache create tmp/pids create Rakefile create README create app/controllers/application_controller.r create app/helpers/application_helper.rb create config/database.yml create config/routes.rb create config/locales/en.yml create db/seeds.rb create config/initializers/backtrace_silencers. create config/initializers/inflections.rb create config/initializers/mime_types.rb create config/initializers/new_rails_defaults.r create config/initializers/session_store.rb create config/initializers/cookie_verification_ create config/environment.rb create config/boot.rb create config/environments/production.rb create config/environments/development.rb create config/environments/test.rb create script/about create script/console create script/dbconsole create script/destroy create script/generate create script/runner create script/server create script/plugin create script/performance/benchmarker create script/performance/profiler create test/test_helper.rb create test/performance/browsing_test.rb create public/404.html create public/422.html create public/500.html create public/index.html create public/favicon.ico create public/robots.txt create public/images/rails.png create public/javascripts/prototype.js create public/javascripts/effects.js create public/javascripts/dragdrop.js create public/javascripts/controls.js create public/javascripts/application.js create doc/README_FOR_APP create log/server.log create log/production.log create log/development.log create log/test.log
执行这个 ruby script/generate migration add_data_to_p,然后再 lib 下 task 里设置完了,执行 rake,不过我的 rake 老报错
你的 rails 是啥版本了,还用这个命令。。
rails g migration add_data_to_p
参考: http://stackoverflow.com/questions/2667580/how-do-i-add-some-inserts-in-rails-migration http://stackoverflow.com/questions/8163509/rails-generate-migration-command-to-insert-data-into-the-table
class Foo < ActiveRecord::Migration
def self.up
Users.new(:username => "Hello", :role => "Admin")
end
def self.down
Users.delete_all(:username => "Hello")
end
end
你的是 rails3 之前的版本,用的./script/下面的命令来生成迁移文件 提示什么错误你也不说,让别人怎么帮你 migration 里加记录没有问题,但一般都不这么填下,写 seed.rb 里