Hello, I developed an app with postgres DB but want to change the DB to sqlite3. I changed the database adapter in the database.yml file. When I run the migration most of it was successful but add_column was throwing an error "Cannot add a NOT NULL column with default value NULL: ALTER TABLE "rates" ADD "customer_id" integer NOT NULL". I made the modification and added the columns to the original migration of the table and ran the migration again. Everything seems to work fine. Why is add_column causing rake to abort during migration? Is there any patch for the problem. Regards, Madhusudhan. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 1 April 2011 12:06, Madhusudhan H R <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hello, > > I developed an app with postgres DB but want to change the DB to > sqlite3. I changed the database adapter in the database.yml file. When I > run the migration most of it was successful but add_column was throwing > an error > > "Cannot add a NOT NULL column with default value NULL: ALTER TABLE > "rates" ADD "customer_id" integer NOT NULL".What is the line in your migration file that throws the error? The error suggests that it says that the column cannot be null, but with a default value of NULL.> > I made the modification and added the columns to the original migration > of the table and ran the migration again. Everything seems to work fine. > > Why is add_column causing rake to abort during migration? Is there any > patch for the problem. > > Regards, > Madhusudhan. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law wrote in post #990365:> On 1 April 2011 12:06, Madhusudhan H R <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Hello, >> >> I developed an app with postgres DB but want to change the DB to >> sqlite3. I changed the database adapter in the database.yml file. When I >> run the migration most of it was successful but add_column was throwing >> an error >> >> "Cannot add a NOT NULL column with default value NULL: ALTER TABLE >> "rates" ADD "customer_id" integer NOT NULL". > > What is the line in your migration file that throws the error? The > error suggests that it says that the column cannot be null, but with a > default value of NULL.Yes the error message is Cannot add a NOT NULL column with default value NULL: ALTER TABLE "rates" ADD "customer_id" integer NOT NULL The migration line which is causing the problem is add_column :rates, :customer_id, :integer, :null => false How can I fix this problem? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 1 April 2011 12:53, Madhusudhan H R <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote in post #990365: >> On 1 April 2011 12:06, Madhusudhan H R <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> Hello, >>> >>> I developed an app with postgres DB but want to change the DB to >>> sqlite3. I changed the database adapter in the database.yml file. When I >>> run the migration most of it was successful but add_column was throwing >>> an error >>> >>> "Cannot add a NOT NULL column with default value NULL: ALTER TABLE >>> "rates" ADD "customer_id" integer NOT NULL". >> >> What is the line in your migration file that throws the error? The >> error suggests that it says that the column cannot be null, but with a >> default value of NULL. > > Yes the error message is Cannot add a NOT NULL column with default value > NULL: ALTER TABLE "rates" ADD "customer_id" integer NOT NULL > > The migration line which is causing the problem is > > add_column :rates, :customer_id, :integer, :null => false > > How can I fix this problem?By providing a default value in the migration. This may be helpful in explaining the issue and suggesting other alternatives. http://strd6.com/2009/04/adding-a-non-null-column-with-no-default-value-in-a-rails-migration/ Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 1 April 2011 12:06, Madhusudhan H R <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I developed an app with postgres DB but want to change the DB to > sqlite3. > > "Cannot add a NOT NULL column with default value NULL: ALTER TABLE > "rates" ADD "customer_id" integer NOT NULL".IIRC the same problem cropped up a couple of months back and it was a ''feature'' of SQLite - it will create tables with "NOT NULL" fields, but won''t allow alters - even if the table is empty Have a check of the archives for similar issues... -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.