开发者

Problems running migrations against users table with Postgresql

I am trying to update some default values for new columns set in a migration. However I am getting a Postgres error whenever I try to do anything with the records of users table (except modify its structure). I am using Rails 3.0.7, ruby 1.9.2 and the pg gem version 0.11.0

Here is the migration:

def self.up
 add_column :users, :state_machine, :string
 add_column :users, :wizard_steps_completed, :integer, :default => "1"
 add_column :users, :activated_at, :datetime

 User.reset_column_information
 User.all.each do |u|
   u.update_attributes(:state_machine => "activated", :wizard_steps_completed => 3, :activated_at => u.created_at)
 end
end

The columns are added with no problems. however the c开发者_运维技巧hanges to existing records all fail with the following error:

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
==  AddUserSignupInfo: migrating ==============================================
rake aborted!
An error has occurred, this and all later migrations canceled:

PGError: ERROR:  current transaction is aborted, commands ignored until end of transaction block
:             SELECT COUNT(*)
            FROM pg_tables
            WHERE tablename = 'users'

If I attempt to update any orecord it seems to work, I can only make structural changes...

Any ideas?


Turn on postgres logging (Configured in /var/lib/pgsql/data/postgresql.conf and grep for "ERROR REPORTING AND LOGGING"). Or you might want to take the SQL and run it yourself to see what error happens. It could be a constraint thats failing because of your update.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜