简体   繁体   English

Rake db:迁移错误“不知道如何构建任务”

[英]Rake db:migrate error “don't know how to build task”

I've got a table where I used integer on a field which needs decimal places, so I'm trying to create a migration which changes the field type from integer to float/real. 我有一个表,我在需要小数位的字段上使用整数,所以我试图创建一个迁移,将字段类型从整数更改为float / real。 My database is sqllite3 and I'm using rails3. 我的数据库是sqllite3,我正在使用rails3。

I ran 我跑了

rails generate migration ChangeMeasureColumnOnIngredients

to create the initial migration files, then updated the class to 创建初始迁移文件,然后将类更新为

class ChangeMeasureColumnOnIngredients < ActiveRecord::Migration
  def self.up
    change_column :ingredients, :measure, :real
  end

I ran rake db:migrate and it returned fine. 我运行了rake db:migrate并且返回正常。

When I inserted a value via my rails app, it didn't return the decimal place. 当我通过我的rails应用程序插入一个值时,它没有返回小数位。 I started to think that many rails doesn't know what 'real' is as a datatype, so I changed the migration to 我开始认为许多rails不知道'real'是什么作为数据类型,因此我将迁移更改为

change_column :ingredients, :measure, :float

I then ran 然后我跑了

rake db:migrate change_measure_column_on_ingredients
and now I get the following error 现在我收到以下错误
 c:\\Ruby192\\rails3rc>rake db:migrate change_measure_column_on_ingredients c:\\ Ruby192 \\ rails3rc> rake db:migrate change_measure_column_on_ingredients\n(in c:/Ruby192/rails3rc) (在c:/ Ruby192 / rails3rc中)\nrake aborted! 耙子流产了!\nDon't know how to build task 'change_measure_column_on_ingredients' 不知道如何构建任务'change_measure_column_on_ingredients'\nC:/Ruby192/lib/ruby/1.9.1/rake.rb:1720:in []' C:/Ruby192/lib/ruby/1.9.1/rake.rb:2040:in C:/Ruby192/lib/ruby/1.9.1/rake.rb:1720:in []' C:/Ruby192/lib/ruby/1.9.1/rake.rb:2040:in []' C:/Ruby192/lib/ruby/1.9.1/rake.rb:2040:in []' C:/Ruby192/lib/ruby/1.9.1/rake.rb:2040:in invoke_task' []' C:/Ruby192/lib/ruby/1.9.1/rake.rb:2040:in invoke_task'\nC:/Ruby192/lib/ruby/1.9.1/rake.rb:2019:in block (2 levels) in top_level' C:/Ruby192/lib/ruby/1.9.1/rake.rb:2019:in C:/Ruby192/lib/ruby/1.9.1/rake.rb:2019:top_level中的block (2 levels) in top_level' C:/Ruby192/lib/ruby/1.9.1/rake.rb:2019:in block (2 levels) in top_level' C:/Ruby192/lib/ruby/1.9.1/rake.rb:2019:in block (2 levels) in top_level' C:/Ruby192/lib/ruby/1.9.1/rake.rb:2019:in each' block (2 levels) in top_level' C:/Ruby192/lib/ruby/1.9.1/rake.rb:2019:in每个'\nC:/Ruby192/lib/ruby/1.9.1/rake.rb:2019:in block in top_level' C:/Ruby192/lib/ruby/1.9.1/rake.rb:2058:in C:/Ruby192/lib/ruby/1.9.1/rake.rb:2011: block in top_level' C:/Ruby192/lib/ruby/1.9.1/rake.rb:2058:in中的block in top_level' C:/Ruby192/lib/ruby/1.9.1/rake.rb:2058:in block in top_level' C:/Ruby192/lib/ruby/1.9.1/rake.rb:2058:in block in top_level' C:/Ruby192/lib/ruby/1.9.1/rake.rb:2058:in standard_exception_handling' block in top_level' C:/Ruby192/lib/ruby/1.9.1/rake.rb:2058:in standard_exception_handling'\nC:/Ruby192/lib/ruby/1.9.1/rake.rb:2013:in top_level' C:/Ruby192/lib/ruby/1.9.1/rake.rb:1992:in C:/Ruby192/lib/ruby/1.9.1/rake.rb:2013:在top_level' C:/Ruby192/lib/ruby/1.9.1/rake.rb:1992:in top_level' C:/Ruby192/lib/ruby/1.9.1/rake.rb:1992:in top_level' C:/Ruby192/lib/ruby/1.9.1/rake.rb:1992:in run' top_level' C:/Ruby192/lib/ruby/1.9.1/rake.rb:1992:in run'\nC:/Ruby192/bin/rake:31:in `' C:/ Ruby192 / bin / rake:31:in'' 

I tried changing the :float back to :real, but I still get that error. 我尝试将:float更改为:real,但我仍然遇到了这个错误。

can somebody tell me what I'm doing wrong? 谁能告诉我我做错了什么? I'm new to rails and still learning. 我是铁杆新手,还在学习。

Your rake call has instructed rake to build the task db:migrate followed by the task change_measure_column_on_ingredients which clearly isn't want you want as the latter is not a rake task. 你的rake调用指示rake构建任务db:migrate后跟任务change_measure_column_on_ingredients ,这显然不是你想要的,因为后者不是rake任务。

To run a specific migration you need to provide the VERSION of the migration. 要运行特定的迁移,您需要提供迁移的VERSION This is the number in the file name which comes before your name for the migration. 这是迁移名称前面的文件名中的数字。 You can migrate it up or down like this: 您可以像这样向上或向下迁移它:

rake db:migrate:down VERSION=123456789
rake db:migrate:up VERSION=123456789

Alternatively you can take the last migration down then up by doing the following (you can also specify a VERSION for this): 或者,您可以通过执行以下操作来向下进行上一次迁移(您还可以为此指定VERSION ):

rake db:migrate:redo

There are other options though. 还有其他选择。 If you run rake --describe db:migrate you'll get some more information. 如果您运行rake --describe db:migrate您将获得更多信息。

While in this specific instance the stacktrace posted by OP shows the error is trying to do two tasks at once, I found this page after googling and just want to add to the answer for future googlers: 虽然在这个特定的例子中,OP发布的堆栈跟踪显示错误正在尝试同时执行两个任务,我在谷歌搜索后找到了这个页面,只是想为未来的googlers添加答案:

try including either RAILS_ENV=development or RAILS_ENV=test as that is what fixed it for me. 尝试包括RAILS_ENV=developmentRAILS_ENV=test因为这是我修复它的原因。

make sure your command is rake db:migrate . 确保你的命令是rake db:migrate Pay attention to there is no any space between : and migrate 注意:migrate之间没有任何空间

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Devise宝石耙中止了! 不知道如何建立任务&#39;db:migrate&#39; - Devise Gem rake aborted! Don't know how to build task 'db:migrate' 不知道如何构建 rake db:migrate on Ubuntu natty? - Don't know how to build rake db:migrate on Ubuntu natty? Rake不知道如何构建任务“ db:migrate” - Rake doesn't know how to build task 'db:migrate' Rake:不知道如何构建任务'db :: create' - Rake: Don't know how to build task 'db::create' 不知道如何在Travis CI中构建任务&#39;db:migrate&#39; - Don't know how to build task 'db:migrate' in Travis CI RoR Rake 10.4.2错误:“不知道如何构建任务&#39;db:&#39;” - RoR Rake 10.4.2 Error: “Don't know how to build task 'db:'” “ Rake :: Task [&#39;db:seed&#39;]。invoke”不起作用-“不知道如何构建任务&#39;db:seed&#39;” - `Rake::Task['db:seed'].invoke` doesn't work - “Don't know how to build task 'db:seed'” 为什么`rake db:seed`失败并显示“不知道如何构建任务&#39;db:seed:original&#39;”? - Why does `rake db:seed` fail with “Don't know how to build task 'db:seed:original'”? Rake db:种子失败,“不知道如何构建任务db.seed” - Rake db:seed fails with 'don't know how to build task db.seed' `rake db:seed:shop:curtain`失败,并显示“不知道如何构建任务&#39;db:seed:shop:curtain&#39;”? - `rake db:seed:shop:curtain` fail with “Don't know how to build task 'db:seed:shop:curtain'”?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM