I’m writing an application and decided late in the game that I needed
authentication, so after viewing Ryan’s railscast, I downloaded the
plugin:
script/plugin source http://svn.techno-weenie.net/projects/plugins/
script/plugin install restful_authentication
script/generate authenticated user session
rake db:migrate
I’m getting the error: rake aborted!
Mysql::Error: Table ‘users’ already exists: CREATE TABLE users (‘id’
int(11) DEFAULT NULL auto_increment PRIMARY KEY) ENGINE=InnoDB
What’s the best way to fix this. Will it work to just migrate back to
version=0 and delete the migration files having to do with a users
table I tried to create on my own in the beginning? or will that just
blow everything up?
Judy Johnson wrote:
I’m writing an application and decided late in the game that I needed
authentication, so after viewing Ryan’s railscast, I downloaded the
plugin:
script/plugin source http://svn.techno-weenie.net/projects/plugins/
script/plugin install restful_authentication
script/generate authenticated user session
rake db:migrate
I’m getting the error: rake aborted!
Mysql::Error: Table ‘users’ already exists: CREATE TABLE users (‘id’
int(11) DEFAULT NULL auto_increment PRIMARY KEY) ENGINE=InnoDB
What’s the best way to fix this. Will it work to just migrate back to
version=0 and delete the migration files having to do with a users
table I tried to create on my own in the beginning? or will that just
blow everything up?
I’m a newbie, so my advice should be considered carefully, but I do know
that if you include “:force => true do |t|” after the create_table
statement (see below), it will basically write over the existing one:
create_table :users, :force => true do |t|
Okay, so I remembered that when I originally ran script/generate
authenticated user session, that I got the message that the
“09_create_users.rb” migrate file already existed. So it wasn’t
overwritten
with the correct file. So I went to script/plugin source
http://svn.techno-weenie.net/projects/plugins/, found the correct file
and
did a copy and paste (inserting “users” where “<%= table_name %>” was,
etc.). Now my migrate file looks like this:
class CreateUsers < ActiveRecord::Migration
def self.up
create_table users, :force => true do |t|
t.column :login, :string
t.column :email, :string
t.column :crypted_password, :string, :limit => 40
t.column :salt, :string, :limit => 40
t.column :created_at, :datetime
t.column :updated_at, :datetime
t.column :remember_token, :string
t.column :remember_token_expires_at, :datetime
t.column :activation_code, :string, :limit => 40
t.column :activated_at, :datetime
end
end
def self.down
drop_table users
end
end
When I run rake db:migrate
I get:
Rake aborted!
Undefined method ‘users’ for
#ActiveRecord::ConnectionAdapters::MysqlAdapter:0x3e259d4
Now I’m really lost. I’m not sure what this error means, so I don’t
know
what to do.
On 15 Nov 2007, at 14:58, Judy Johnson wrote:
Rake aborted!
Undefined method ‘users’ for
#ActiveRecord::ConnectionAdapters::MysqlAdapter:0x3e259d4
Now I’m really lost. I’m not sure what this error means, so I don’t
know
what to do.
It means there is no method or local variable called users. You’ve
typoed the above, you meant to write :users and not users.
Fred