Entries tagged with “migrations”.


Problem
To get used to the new ways of working with Rails 2.

Solution
Here are some of the new ways of doing things in Rails 2.

  1. Create a scaffold and migration on one step:
    ./script/generate scaffold product fied1_name:string field2_name:string field3_name:float

    Make sure that you don’t have any previous migration(ie manually created) for the same model, as the generator will stop and won’t overwrite the previous migration.

Problem
When using cap deploy_with_migrations, the default behaviour is to deploy with the migrations in the production environment.

Solution
To change this behavior add:

set  :rails_env,  "development"

in your config/deploy.rb

After spending some time trying to make a migration work, and having the error message coming back:

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]

I’ve decided to do a google search for the specific problem, as it was working fine with other test migrations.

It turns out that if the migration is not model specific, but a different one (ie trying to add a new column to an existing table), the :int for the column doesn’t work!
It has to be :integer.
Full bug report and the article are here:
Migrations: :integer works, :int doesn’t – datatype discrepancy