# Database names

**URL:** <https://www.ruby-forum.com/t/database-names/158864>\
**Category:** Rails\
**Created:** [January 28, 2009, 9:44pm UTC](https://www.ruby-forum.com/t/database-names/158864 "2009-01-28T21:44:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [January 28, 2009, 9:44pm UTC](https://www.ruby-forum.com/t/database-names/158864/1 "2009-01-28T21:44:43Z")

</div>

If I generate a model by: “./script generate model user” it make a table  
“users”.  
But if I want that table is “user” not “users” what I can do?

---

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [January 28, 2009, 10:48pm UTC](https://www.ruby-forum.com/t/database-names/158864/2 "2009-01-28T22:48:42Z")

</div>

James B. wrote:

> If I generate a model by: “./script generate model user” it make a table  
> “users”.  
> But if I want that table is “user” not “users” what I can do?

You can override the default table name in your migration file after  
running the generator.

However, if I had anything to say about it I would not allow a developer  
to break this Rails convention. The only allowable exception would be in  
the case of a pre-existing database schema that is being used somewhere  
outside the Rails project.

But, if you want to go to all the extra trouble to break with  
convention, Rails will certainly let you do so.

You need to change the table name in the migration and also set the  
table name in the model so it knows what to look for:

## Example:

class Project \< ActiveRecord::Base  
set\_table\_name “project”  
end

class CreateProjects \< ActiveRecord::Migration  
def self.up  
create\_table :project do |t| # Note singular form  
t.string :name  
t.text :description

```
  t.timestamps
end

```

end

def self.down  
drop\_table :project # And here too  
end  
end

---

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [January 28, 2009, 10:50pm UTC](https://www.ruby-forum.com/t/database-names/158864/3 "2009-01-28T22:50:00Z")

</div>

James B. wrote:

> If I generate a model by: “./script generate model user” it make a table  
> “users”.  
> But if I want that table is “user” not “users” what I can do?

Think this is what you’re looking for:

[http://wiki.rubyonrails.org/rails/pages/howtouselegacyschemas](http://wiki.rubyonrails.org/rails/pages/howtouselegacyschemas)

Cheers  
Luke
