# Rails keeps adding the letter s to the MySQL tablename

**URL:** <https://www.ruby-forum.com/t/rails-keeps-adding-the-letter-s-to-the-mysql-tablename/62604>\
**Category:** Rails\
**Created:** [June 6, 2006, 3:47pm UTC](https://www.ruby-forum.com/t/rails-keeps-adding-the-letter-s-to-the-mysql-tablename/62604 "2006-06-06T15:47:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaypee68](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e8c25b/32.png) [@jaypee68](https://www.ruby-forum.com/u/jaypee68)\
**Post date:** [June 6, 2006, 3:47pm UTC](https://www.ruby-forum.com/t/rails-keeps-adding-the-letter-s-to-the-mysql-tablename/62604/1 "2006-06-06T15:47:45Z")

</div>

I followed this tutorial for Ruby on Rails…

> **[Radar - O’Reilly](https://www.oreilly.com/radar/?page=1)**
>
> Now, next, and beyond: Tracking need-to-know trends at the intersection of business and technology

Everything went fine. I created the DB in MySQL and tested the  
recipe/new and recipe/list functions, and all went smooth.

Now I’m trying to use Ruby on Rails to track software licenses here at  
work and I keep running into this strange problem. I am setting up the  
DB, model, and controller files just fine…

development:  
adapter: mysql  
database: gcsaam  
username: root  
password:  
host: localhost

# Warning: The database defined as ‘test’ will be erased and

# re-generated from your development database when you run ‘rake’.

# Do not set this db to the same as development or production.

test:  
adapter: mysql  
database: gcsaam  
username: root  
password:  
host: localhost

production:  
adapter: mysql  
database: gcsaam  
username: root  
password:  
host: localhost

softlic.rb

class Softlic \< ActiveRecord::Base  
end

softlic\_controller.rb

class SoftlicController \< ApplicationController  
scaffold :softlic  
end

So here is my problem. Ruby or maybe Rails, keeps addign the letter “s”  
to the MySQL table name like it shows here…

ActiveRecord::StatementInvalid in SoftlicController#new

Mysql::Error: #42S02Table ‘gcsaam.softlics’ doesn’t exist: SHOW FIELDS  
FROM softlics

RAILS\_ROOT: ./script/…/config/…

My table name is softlic, not softlics. I’ve been at this for a day and  
a half and am about to toss something across the room. 🙂 I am totally  
stumped here. I even thought maybe it was a bug issue with 1.8.4-17 so  
I downgraded to 1.8.2-15. Does anybody know what my problem might be?  
Am I missing some small morsel of info here? My new project is pretty  
much a mirror image of the cookbook example with the exception of  
filename changes and different fields in the DB. Help! 🙂 Thank You.

---

<div class="post-metadata">

**Author:** ![jaypee68](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e8c25b/32.png) [@jaypee68](https://www.ruby-forum.com/u/jaypee68)\
**Post date:** [June 6, 2006, 3:54pm UTC](https://www.ruby-forum.com/t/rails-keeps-adding-the-letter-s-to-the-mysql-tablename/62604/2 "2006-06-06T15:54:50Z")

</div>

On Jun 6, 2006, at 9:47 AM, Jean-Paul Ladue wrote:

> DB, model, and controller files just fine…
> 
> # Do not set this db to the same as development or production.
> 
> username: root  
> class SoftlicController \< ApplicationController  
> FROM softlics  
> Am I missing some small morsel of info here? My new project is pretty  
> much a mirror image of the cookbook example with the exception of  
> filename changes and different fields in the DB. Help! 🙂 Thank  
> You.

You can turn this off by adding the following to your config/  
environment.rb file:  
ActiveRecord::Base.pluralize\_table\_names = false

---

<div class="post-metadata">

**Author:** ![jaypee68](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e8c25b/32.png) [@jaypee68](https://www.ruby-forum.com/u/jaypee68)\
**Post date:** [June 6, 2006, 3:58pm UTC](https://www.ruby-forum.com/t/rails-keeps-adding-the-letter-s-to-the-mysql-tablename/62604/3 "2006-06-06T15:58:47Z")

</div>

Jean-Paul Ladue wrote:

> test:  
> password:  
> scaffold :softlic  
> RAILS\_ROOT: ./script/…/config/…
> 
> My table name is softlic, not softlics. I’ve been at this for a day and  
> a half and am about to toss something across the room. 🙂 I am totally  
> stumped here. I even thought maybe it was a bug issue with 1.8.4-17 so  
> I downgraded to 1.8.2-15. Does anybody know what my problem might be?  
> Am I missing some small morsel of info here? My new project is pretty  
> much a mirror image of the cookbook example with the exception of  
> filename changes and different fields in the DB. Help! 🙂 Thank You.

It’s not a bug, it’s a feature! 🙂

You may have noticed that the ONLamp tutorial used “recipes” as the name  
of the table, but accessed it using “recipe” when scaffolding. RoR  
likes to maintain data in tables that are plurals of the basic record.  
So, the class “item” goes into a table called “itemS”, class “recipe”  
into “recipes” and so on…

Your table needs to be name with an “s” - that’s all 🙂

Or you follow the other mail’s suggestion and disable pluralized names.  
Cheers  
Mohit.

---

<div class="post-metadata">

**Author:** ![jaypee68](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e8c25b/32.png) [@jaypee68](https://www.ruby-forum.com/u/jaypee68)\
**Post date:** [June 6, 2006, 4:21pm UTC](https://www.ruby-forum.com/t/rails-keeps-adding-the-letter-s-to-the-mysql-tablename/62604/4 "2006-06-06T16:21:41Z")

</div>

Hi Jean-Paul,

Jean-Paul Ladue wrote:

> So here is my problem. Ruby or maybe Rails,  
> keeps addign the letter “s” to the MySQL table  
> name like it shows here…
> 
> Mysql::Error: #42S02Table ‘gcsaam.softlics’ doesn’t exist

> My table name is softlic, not softlics.

> Am I missing some small morsel of info here? \> Rails mailing list

RoR favors convention over configuration. This is one of the biggies.

Table names are plural version of the model names because a model object  
represents one row in a table. It’s a fundamental convention that’s a  
reflection of the Active Record pattern. In your case, the table  
contains a  
collection of software licenses. Each model object represents one  
software  
license. Makes sense, no?

There are ways, as noted by other responders, to over-ride the behavior.  
It’s not advisable except in extreme circumstances.

Learn it. You’ll love it! 😉

hth,  
Bill

---

<div class="post-metadata">

**Author:** ![jaypee68](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e8c25b/32.png) [@jaypee68](https://www.ruby-forum.com/u/jaypee68)\
**Post date:** [June 6, 2006, 4:26pm UTC](https://www.ruby-forum.com/t/rails-keeps-adding-the-letter-s-to-the-mysql-tablename/62604/5 "2006-06-06T16:26:25Z")

</div>

Thanks guys, everything is as smooth as silk now. I had read about the  
pluralization but wasn’t aware that it worked this way. Thanks again  
and you’ll probably see me again soon. 🙂
