# Table 'users' already exists

**URL:** <https://www.ruby-forum.com/t/table-users-already-exists/120286>\
**Category:** Rails\
**Created:** [November 15, 2007, 3:24pm UTC](https://www.ruby-forum.com/t/table-users-already-exists/120286 "2007-11-15T15:24:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Judy\_Johnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@Judy\_Johnson](https://www.ruby-forum.com/u/Judy_Johnson)\
**Post date:** [November 15, 2007, 3:24pm UTC](https://www.ruby-forum.com/t/table-users-already-exists/120286/1 "2007-11-15T15:24:04Z")

</div>

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/](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?

---

<div class="post-metadata">

**Author:** ![Judy\_Johnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@Judy\_Johnson](https://www.ruby-forum.com/u/Judy_Johnson)\
**Post date:** [November 15, 2007, 3:27pm UTC](https://www.ruby-forum.com/t/table-users-already-exists/120286/2 "2007-11-15T15:27:57Z")

</div>

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/](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|

---

<div class="post-metadata">

**Author:** ![Judy\_Johnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@Judy\_Johnson](https://www.ruby-forum.com/u/Judy_Johnson)\
**Post date:** [November 15, 2007, 4:00pm UTC](https://www.ruby-forum.com/t/table-users-already-exists/120286/3 "2007-11-15T16:00:29Z")

</div>

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/](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.

---

<div class="post-metadata">

**Author:** ![Judy\_Johnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@Judy\_Johnson](https://www.ruby-forum.com/u/Judy_Johnson)\
**Post date:** [November 15, 2007, 4:02pm UTC](https://www.ruby-forum.com/t/table-users-already-exists/120286/4 "2007-11-15T16:02:15Z")

</div>

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
