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:ininvoke_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:ineach' C:/Ruby192/lib/ruby/1.9.1/rake.rb:2019:inblock in top_level' C:/Ruby192/lib/ruby/1.9.1/rake.rb:2058:instandard_exception_handling' C:/Ruby192/lib/ruby/1.9.1/rake.rb:2013:intop_level' C:/Ruby192/lib/ruby/1.9.1/rake.rb:1992:inrun' 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:migratefollowed by the taskchange_measure_column_on_ingredientswhich clearly isn’t want you want as the latter is not a rake task.To run a specific migration you need to provide the
VERSIONof 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:Alternatively you can take the last migration down then up by doing the following (you can also specify a
VERSIONfor this):There are other options though. If you run
rake --describe db:migrateyou’ll get some more information.