Rake db:migrate 错误“不知道如何构建任务" [英] Rake db:migrate error "don't know how to build task"
问题描述
我有一个表,我在需要小数位的字段上使用整数,所以我尝试创建一个迁移,将字段类型从整数更改为浮点/实数.我的数据库是 sqllite3,我使用的是 rails3.
我跑了
<前>rails 生成迁移 ChangeMeasureColumnOnIngredients创建初始迁移文件,然后将类更新为
<前>类 ChangeMeasureColumnOnIngredients我运行了 rake db:migrate 并且它返回正常.
当我通过 rails 应用程序插入一个值时,它没有返回小数位.我开始认为许多 Rails 不知道什么是真实"作为数据类型,因此我将迁移更改为
change_column :ingredients, :measure, :float
然后我运行
rake db:migrate change_measure_column_on_ingredients
现在我收到以下错误
c:\Ruby192\rails3rc>rake db:migrate change_measure_column_on_ingredients(在 c:/Ruby192/rails3rc 中)耙子中止!不知道如何构建任务change_measure_column_on_ingredients"C:/Ruby192/lib/ruby/1.9.1/rake.rb:1720:in[]'C:/Ruby192/lib/ruby/1.9.1/rake.rb:2040:in
invoke_task'C:/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
each'C:/Ruby192/lib/ruby/1.9.1/rake.rb:2019:inblock in top_level'C:/Ruby192/lib/ruby/1.9.1/rake.rb:2058:in
standard_exception_handling'C:/Ruby192/lib/ruby/1.9.1/rake.rb:2013:intop_level'C:/Ruby192/lib/ruby/1.9.1/rake.rb:1992:in
run'C:/Ruby192/bin/rake:31:in `'
我尝试将 :float 改回 :real,但我仍然遇到该错误.
有人能告诉我我做错了什么吗?我是 Rails 的新手,仍在学习.
您的 rake 调用已指示 rake 构建任务 db:migrate
后跟任务 change_measure_column_on_ingredients
显然不是你想要的,因为后者不是一个耙子任务.
要运行特定的迁移,您需要提供迁移的 VERSION
.这是文件名中位于迁移名称之前的数字.您可以像这样向上或向下迁移:
rake db:migrate:down VERSION=123456789耙 db:migrate:up 版本=123456789
或者,您可以通过执行以下操作将最后一次迁移向下然后向上(您也可以为此指定 VERSION
):
rake db:migrate:redo
不过还有其他选择.如果您运行 rake --describe db:migrate
,您将获得更多信息.
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. My database is sqllite3 and I'm using 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.
When I inserted a value via my rails app, it didn't return the decimal place. I started to think that many rails doesn't know what 'real' is as a datatype, so I changed the migration to
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 (in c:/Ruby192/rails3rc) rake aborted! Don't know how to build task 'change_measure_column_on_ingredients' C:/Ruby192/lib/ruby/1.9.1/rake.rb:1720:in[]' C:/Ruby192/lib/ruby/1.9.1/rake.rb:2040:in
invoke_task' C:/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
each' C:/Ruby192/lib/ruby/1.9.1/rake.rb:2019:inblock in top_level' C:/Ruby192/lib/ruby/1.9.1/rake.rb:2058:in
standard_exception_handling' C:/Ruby192/lib/ruby/1.9.1/rake.rb:2013:intop_level' C:/Ruby192/lib/ruby/1.9.1/rake.rb:1992:in
run' C:/Ruby192/bin/rake:31:in `'
I tried changing the :float back to :real, but I still get that error.
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.
To run a specific migration you need to provide the VERSION
of the migration. 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):
rake db:migrate:redo
There are other options though. If you run rake --describe db:migrate
you'll get some more information.
这篇关于Rake db:migrate 错误“不知道如何构建任务"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!