Hi all. I''ve upgraded my Rails yesterday and trying to use the following code: $ script/generate scaffold Email user:references email:string I got, in my database:> show fields from emails;+------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | user_id | int(11) | YES | | NULL | | | email | varchar(255) | NO | | NULL | | [...] and in my migration: [...] create_table :emails do |t| t.references :user t.string :email [...] But I can''t test anything! I''m getting: test_truth(EmailTest): ActiveRecord::StatementInvalid: Mysql::Error: Unknown column ''user'' in ''field list'': INSERT INTO `emails` (`user`,`email`) VALUES (NULL,''MyString'') What I''m doing wrong? Thank you very much. -- Davi Vidal -- E-mail: davividal-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org MSN : davividal-uAjRD0nVeow@public.gmane.org GTalk : davividal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Skype : davi vidal ICQ : 138815296
Rick DeNatale
2007-Dec-14 18:35 UTC
Re: Trouble with tests + sexy migrations [Rails 2.0.1]
On 12/14/07, Davi <davividal-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org> wrote:> > Hi all. I''ve upgraded my Rails yesterday and trying to use the following > code: > > $ script/generate scaffold Email user:references email:string > > I got, in my database: > > > show fields from emails; > +------------+--------------+------+-----+---------+----------------+ > | Field | Type | Null | Key | Default | Extra | > +------------+--------------+------+-----+---------+----------------+ > | id | int(11) | NO | PRI | NULL | auto_increment | > | user_id | int(11) | YES | | NULL | | > | email | varchar(255) | NO | | NULL | | > [...] > > and in my migration: > > [...] > create_table :emails do |t| > t.references :user > t.string :email > [...] > > > But I can''t test anything! I''m getting: > > test_truth(EmailTest): > ActiveRecord::StatementInvalid: Mysql::Error: Unknown column ''user'' in ''field > list'': INSERT INTO `emails` (`user`,`email`) VALUES (NULL,''MyString'') > > What I''m doing wrong? > > Thank you very much.Are you confusing your test database with your development database. I suspect that you''ve only run the migrations against the latter. You probably need to do something like rake db:test:prepare -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2007-Dec-14 18:45 UTC
Re: Trouble with tests + sexy migrations [Rails 2.0.1]
On Dec 14, 2:54 pm, Davi <davivi...-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org> wrote:> > show fields from emails; > > +------------+--------------+------+-----+---------+----------------+ > | Field | Type | Null | Key | Default | Extra | > +------------+--------------+------+-----+---------+----------------+ > | id | int(11) | NO | PRI | NULL | auto_increment | > | user_id | int(11) | YES | | NULL | | > | email | varchar(255) | NO | | NULL | | > [...] >> test_truth(EmailTest): > ActiveRecord::StatementInvalid: Mysql::Error: Unknown column ''user'' in ''field > list'': INSERT INTO `emails` (`user`,`email`) VALUES (NULL,''MyString'') >What''s in your fixtures file? If you''ve got user: then that''s your problem, since you have no user column, only a user_id column Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Em Sex 14 Dez 2007, Rick DeNatale escreveu:> On 12/14/07, Davi <davividal-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org> wrote: > > Hi all. I''ve upgraded my Rails yesterday and trying to use the > > following code: > > > > $ script/generate scaffold Email user:references email:string > > > > I got, in my database: > > > show fields from emails; > > > > +------------+--------------+------+-----+---------+----------------+ > > > > | Field | Type | Null | Key | Default | Extra | > > > > +------------+--------------+------+-----+---------+----------------+ > > > > | id | int(11) | NO | PRI | NULL | auto_increment | > > | user_id | int(11) | YES | | NULL | | > > | email | varchar(255) | NO | | NULL | | > > > > [...] > > > > and in my migration: > > > > [...] > > create_table :emails do |t| > > t.references :user > > t.string :email > > [...] > > > > > > But I can''t test anything! I''m getting: > > > > test_truth(EmailTest): > > ActiveRecord::StatementInvalid: Mysql::Error: Unknown column ''user'' in > > ''field list'': INSERT INTO `emails` (`user`,`email`) VALUES > > (NULL,''MyString'') > > > > What I''m doing wrong? > > > > Thank you very much. > > Are you confusing your test database with your development database. > I suspect that you''ve only run the migrations against the latter. > > You probably need to do something like > > rake db:test:prepareAlready did it. I''ve already run rake db:create:all, rake db:test:prepare and I''ve tried rake db:test:clone_structure. My test database was created fine with all tables, but I can''t understand what is going on with field names... Thanks, -- Davi Vidal -- E-mail: davividal-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org MSN : davividal-uAjRD0nVeow@public.gmane.org GTalk : davividal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Skype : davi vidal ICQ : 138815296
Rick DeNatale
2007-Dec-14 19:31 UTC
Re: Trouble with tests + sexy migrations [Rails 2.0.1]
On 12/14/07, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On Dec 14, 2:54 pm, Davi <davivi...-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org> wrote: > > > show fields from emails; > > > > +------------+--------------+------+-----+---------+----------------+ > > | Field | Type | Null | Key | Default | Extra | > > +------------+--------------+------+-----+---------+----------------+ > > | id | int(11) | NO | PRI | NULL | auto_increment | > > | user_id | int(11) | YES | | NULL | | > > | email | varchar(255) | NO | | NULL | | > > [...] > > > > > test_truth(EmailTest): > > ActiveRecord::StatementInvalid: Mysql::Error: Unknown column ''user'' in ''field > > list'': INSERT INTO `emails` (`user`,`email`) VALUES (NULL,''MyString'') > > > What''s in your fixtures file? If you''ve got user: then that''s your > problem, since you have no user column, only a user_id columnYes, that''s probably right, unless he''s using Rails 2.0 where you can use symbolic relationship values: users.yml fred: name: Fred ... _END_ emails: user: fred email: Hi Fred _END_ But in that case, it would be inserting into the user_id field instead of the user field. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.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 -~----------~----~----~----~------~----~------~--~---
Em Sex 14 Dez 2007, Rick DeNatale escreveu:> On 12/14/07, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > On Dec 14, 2:54 pm, Davi <davivi...-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org> wrote: > > > > show fields from emails; > > > > > > +------------+--------------+------+-----+---------+----------------+ > > > > > > | Field | Type | Null | Key | Default | Extra | > > > > > > +------------+--------------+------+-----+---------+----------------+ > > > > > > | id | int(11) | NO | PRI | NULL | auto_increment | > > > | user_id | int(11) | YES | | NULL | | > > > | email | varchar(255) | NO | | NULL | | > > > > > > [...] > > > > > > > > > test_truth(EmailTest): > > > ActiveRecord::StatementInvalid: Mysql::Error: Unknown column ''user'' in > > > ''field list'': INSERT INTO `emails` (`user`,`email`) VALUES > > > (NULL,''MyString'') > > > > What''s in your fixtures file? If you''ve got user: then that''s your > > problem, since you have no user column, only a user_id columnYeah! The problem was in fixtures files... I''ve changed from user: to user_id: and all is working fine. Thanks.> > Yes, that''s probably right, unless he''s using Rails 2.0 where you can > use symbolic relationship values: > > users.yml > > fred: > name: Fred > ... > _END_ > > emails: > user: fred > email: Hi Fred > _END_ > > But in that case, it would be inserting into the user_id field instead > of the user field.I''m using Rails 2.0, but all fields was empty. I''ll try go back from user_id: to user: and fill some info. I''ll post results... Thank you all. -- Davi Vidal -- E-mail: davividal-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org MSN : davividal-uAjRD0nVeow@public.gmane.org GTalk : davividal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Skype : davi vidal ICQ : 138815296
Anna Callahan
2008-May-21 16:09 UTC
Re: Trouble with tests + sexy migrations [Rails 2.0.1]
Is there a belongs_to association in your Email model? Lacking that would cause this error. Davi wrote:> Em Sex 14 Dez 2007, Rick DeNatale escreveu: > > I''m using Rails 2.0, but all fields was empty. > > I''ll try go back from user_id: to user: and fill some info. I''ll post > results... > > Thank you all. >-- 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 -~----------~----~----~----~------~----~------~--~---