Hi, While adding a new entry in my database , if i dnt enter one of the field, it gets stored as emtry string and not as NULL field.This creates some problem while searching on that model. How can i deal with it?? Thanks, Sup -- View this message in context: http://www.nabble.com/empty-emtry-in-database-problem-tp18193221p18193221.html Sent from the RubyOnRails Users mailing list archive at Nabble.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?hl=en -~----------~----~----~----~------~----~------~--~---
Hi In migration file you can speciy like :null => true If false, the underlying column has a not null constraint added (if the database supports it). You can use like t.column :name_last, :string, :null=>true (for example) And already migration file exists you can change column type using change_column Sijo -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
sorry but that i alreayd tried.. not working .. still saving a field as empty in database.!! :( On Mon, Jun 30, 2008 at 5:28 PM, Sijo Kg <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi > In migration file you can speciy like > :null => true > > If false, the underlying column has a not null constraint added (if the > database supports it). > > You can use like > t.column :name_last, :string, :null=>true (for example) > > > And already migration file exists you can change column type using > change_column > > Sijo > -- > 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?hl=en -~----------~----~----~----~------~----~------~--~---
You are probably setting the attribute to an empty string before saving the record/model instance. How is the attribute being populated? Empty string is still valid (not null)... On Jun 30, 8:15 am, "supriya agarwal" <supriya.ii...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> sorry but that i alreayd tried.. not working .. still saving a field as > empty in database.!! :( > > On Mon, Jun 30, 2008 at 5:28 PM, Sijo Kg <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > > > Hi > > In migration file you can speciy like > > :null => true > > > If false, the underlying column has a not null constraint added (if the > > database supports it). > > > You can use like > > t.column :name_last, :string, :null=>true (for example) > > > And already migration file exists you can change column type using > > change_column > > > Sijo > > -- > > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
im not setting it anywhere, it is just getting added through basic code of: @device = Dev.new(@params[:dev]) and after that checking @device.save and then redirecting_to some page. if im not entering anything nothing gets added. my point is it shud get added as NULL in database. should''nt it?? On Mon, Jun 30, 2008 at 6:27 PM, Harold <harold.gimenez-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > You are probably setting the attribute to an empty string before > saving the record/model instance. How is the attribute being > populated? > > Empty string is still valid (not null)... > > > On Jun 30, 8:15 am, "supriya agarwal" <supriya.ii...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > sorry but that i alreayd tried.. not working .. still saving a field as > > empty in database.!! :( > > > > On Mon, Jun 30, 2008 at 5:28 PM, Sijo Kg < > rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > > > > > > > > > Hi > > > In migration file you can speciy like > > > :null => true > > > > > If false, the underlying column has a not null constraint added (if the > > > database supports it). > > > > > You can use like > > > t.column :name_last, :string, :null=>true (for example) > > > > > And already migration file exists you can change column type using > > > change_column > > > > > Sijo > > > -- > > > Posted viahttp://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?hl=en -~----------~----~----~----~------~----~------~--~---
On 30 Jun 2008, at 14:15, supriya agarwal wrote:> im not setting it anywhere, it is just getting added through basic > code of: > > @device = Dev.new(@params[:dev]) > and after that checking @device.save and then redirecting_to some > page. > > if im not entering anything nothing gets added. my point is it shud > get added as NULL in database. should''nt it?? >By nothing do you mean that there is a corresponding text field which you have left empty? That will submit an empty string. If you want to coerce those to nulls you''ll have to do it yourself Fred> On Mon, Jun 30, 2008 at 6:27 PM, Harold <harold.gimenez-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > You are probably setting the attribute to an empty string before > saving the record/model instance. How is the attribute being > populated? > > Empty string is still valid (not null)... > > > On Jun 30, 8:15 am, "supriya agarwal" <supriya.ii...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > sorry but that i alreayd tried.. not working .. still saving a > field as > > empty in database.!! :( > > > > On Mon, Jun 30, 2008 at 5:28 PM, Sijo Kg <rails-mailing- > l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > > > > > > > > > Hi > > > In migration file you can speciy like > > > :null => true > > > > > If false, the underlying column has a not null constraint added > (if the > > > database supports it). > > > > > You can use like > > > t.column :name_last, :string, :null=>true (for example) > > > > > And already migration file exists you can change column type using > > > change_column > > > > > Sijo > > > -- > > > Posted viahttp://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?hl=en -~----------~----~----~----~------~----~------~--~---