Joe Ruby MUDCRAP-CE
2006-Oct-15 20:12 UTC
Migrations - add_column :default=>true, :null=>false
This seems pretty brain dead: add_column :types, :notify_on_create, :boolean, {:default=>true, :null=>false} $ rake migrate Error: ERROR: column "notify_on_create" contains null values : ALTER TABLE types ALTER notify_on_create SET NOT NULL Why doesn''t Rails set the new column to true, as it''s supposed to default to? I tried :default=>1 as well (same results). Is there a way to make this migration work? Joe -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Lionel Bouton
2006-Oct-15 20:19 UTC
Re: Migrations - add_column :default=>true, :null=>false
Joe Ruby MUDCRAP-CE wrote the following on 15.10.2006 22:12 :> This seems pretty brain dead: > > add_column :types, :notify_on_create, :boolean, {:default=>true, > :null=>false} > > $ rake migrate > > Error: ERROR: column "notify_on_create" contains null values > : ALTER TABLE types ALTER notify_on_create SET NOT NULL > > Why doesn''t Rails set the new column to true, as it''s supposed to > default to? I tried :default=>1 as well (same results). > > Is there a way to make this migration work? > > Joe > >Do you use PostgreSQL by any chance? Try to load this in your environment.rb: # add_column in the original PostgreSQLAdapter # begins by creating the column and then adds constraints # which simply doesn''t work... AbstractAdapter is ok -> super works class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter def add_column(table_name, column_name, type, options = {}) super end end Lionel --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Joe Ruby MUDCRAP-CE
2006-Oct-15 20:28 UTC
Re: Migrations - add_column :default=>true, :null=>false
Here''s a workaround: def self.up # add_column :types, :notify_on_create, :boolean, {:default=>true, :null=>false} add_column :types, :notify_on_create, :boolean, :default=>true # Type.reset_column_information # doesn''t seem necessary? Type.update_all ''notify_on_create=true'' change_column :types, :notify_on_create, :boolean, :null=>false # doesn''t change anything end As you can see from my comments, reset_column_information doesn''t seem necessary (contrary to the docs). And the last change_column doesn''t result in the notify_on_create column getting changed to not null. Sigh...time to submit some tickets I guess. Joe -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Joe Ruby MUDCRAP-CE
2006-Oct-16 21:22 UTC
Re: Migrations - add_column :default=>true, :null=>false
This appears to be fixed in HEAD (way back in July). Anybody know how to execute this statement in script/console? I can''t figure out how. alter table types alter notify_on_create set not null Thanks, Joe -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---