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:
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:
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
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
Already 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,
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.
> > > 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
Yeah! 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.
Is there a belongs_to association in your Email model? Lacking that would cause this error.
Davi wrote: