[英]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_ingredientsand now I get the following error
c:\\Ruby192\\rails3rc>rake db:migrate change_measure_column_on_ingredientsc:\\ 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:inblock (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:inblock 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:intop_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=development
或RAILS_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.