Error in Migration

Hi all,
  I have an error while running the migration. The following is the
problem.
I have a table called sequences. Am adding a column called 'seq_type'
in migration Version 79. and after adding am also inserting a row in the
table, then its throwing an error called "undefined method seq_type= for
<Sequence:0x4cab0f8>"

This is my code.

def self.up
  add_column :sequences, :seq_type, :integer, :limit => 1
  Sequence.create(:user_id => 1, :seq_type => 2)
end

Column is getting added, but the row is not getting created. when I run
the migration again by commenting the first line , then its working
properly.
Why it is not working for the first time?
I also tried to put the row creation in the next migration, even then
its failing.

What could be the reason?? It it not detecting the column? If not what
to do??

Kindly please help me..

I don’t think that ActiveRecord, of which your Sequence is a subclass, knows yet about the new column. Anyway, it’s a good idea to use models in migrations as little as possible so that changes in models don’t break older migrations. I’d recommend using SQL to add the data if you want to add it in this migration. If the data is seed data, i.e., it’s basic data that needs to be there for your application to run, I’d recommend using one of the many data seeding techniques that have been discussed/announced in the group before.

Regards,
Craig

I don't think that ActiveRecord, of which your Sequence is a
subclass, knows yet about the new column.

If that's the case, Sequence.reset_column_information should sort
things out.

Fred

Hi,
  Thanks a lot.. I used Sequence.reset_column_information and its
working perfectly..
Cheers..
Naga Harish Kanegolla

Frederick Cheung wrote: