# Try creating a table for your model

**URL:** <https://www.ruby-forum.com/t/try-creating-a-table-for-your-model/65039>\
**Category:** Rails\
**Created:** [August 15, 2006, 7:54pm UTC](https://www.ruby-forum.com/t/try-creating-a-table-for-your-model/65039 "2006-08-15T19:54:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [August 15, 2006, 7:54pm UTC](https://www.ruby-forum.com/t/try-creating-a-table-for-your-model/65039/1 "2006-08-15T19:54:15Z")

</div>

Railers:

Greetings from the low end of the learning curve. I have installed all  
the prerequisites on Win32, including a lite MySQL database with a  
table in it called Inventory.

Then I run this command line…

```
ruby script/generate ajax_scaffold Inventory

```

…and I get this error message:

error Before updating scaffolding from new DB schema, try creating  
a table for your model (Inventory)

So I read log/development.log, and it contains this:

Error: Table ‘rails\_development.inventories’ doesn’t exist

The system is inexplicably pluralizing my table name. Am I using the  
system wrong, or is this a false “feature”?

Can I fix it by adding a view called ‘inventories’? Or must I rename the  
table?

And how, in general, can Rails present data views that don’t have the  
same shape as the target database schema? Such schemas should be  
normalized beyond recognition…

---

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [August 15, 2006, 8:12pm UTC](https://www.ruby-forum.com/t/try-creating-a-table-for-your-model/65039/2 "2006-08-15T20:12:17Z")

</div>

> error Before updating scaffolding from new DB schema, try creating  
> table?
> 
> And how, in general, can Rails present data views that don’t have the  
> same shape as the target database schema? Such schemas should be  
> normalized beyond recognition…

These might come in handy…

Rails HowTo: Pluralizing  
[http://www.slash7.com/articles/2005/11/17/rails-howto-pluralizing](http://www.slash7.com/articles/2005/11/17/rails-howto-pluralizing)

Riding Rails: 10 Reasons Rails Does Pluralization  
[http://weblog.rubyonrails.com/2005/08/25/10-reasons-rails-does-pluralization/](http://weblog.rubyonrails.com/2005/08/25/10-reasons-rails-does-pluralization/)

> **[ActiveRecord::Base](https://api.rubyonrails.org/classes/ActiveRecord/Base.html#M000880)**
>
> Active Record Active Record objects don't specify their attributes directly, but rather infer them from the table definition with which they're linked.

---

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [August 15, 2006, 8:33pm UTC](https://www.ruby-forum.com/t/try-creating-a-table-for-your-model/65039/3 "2006-08-15T20:33:23Z")

</div>

Hi Philip,

The table/model naming isn’t a “false” feature, but a feature 🙂 You  
don’t  
have to create a view or rename the table, though your life will be made  
easier if your table names are pluralized. If you want to use a table  
name  
that Rails doesn’t expect, you can use “set\_table\_name ‘inventory’” in  
your  
model class. And yes, you can have models which correspond to views -  
I’m  
not sure what operations you can perform, but I know you can at least  
read  
rows from the view.

---

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [August 15, 2006, 8:39pm UTC](https://www.ruby-forum.com/t/try-creating-a-table-for-your-model/65039/4 "2006-08-15T20:39:27Z")

</div>

Philip H. wrote:

> Riding Rails: 10 Reasons Rails Does Pluralization  
> [Peak Obsession](http://weblog.rubyonrails.com/2005/08/25/10-reasons-rails-does-pluralization/)

And, uh, adding a single line to the default Rails page would have …  
prevented the need for such a clever page? And its attendant FAQ?

---

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [August 15, 2006, 8:51pm UTC](https://www.ruby-forum.com/t/try-creating-a-table-for-your-model/65039/5 "2006-08-15T20:51:33Z")

</div>

Phlip wrote:

> before Ruby existed…

I may be missing something here (and a search to see your earlier post  
reveals that you were using AjaxScaffold) but as I understand it, you  
can always create a model without creating the table name in plural.

In the way I know it:  
dir\>ruby script\generate model Inventory

- this will create the model ‘inventory’ (app\models\inventory.rb) and a  
migration that will db\migrate\xxx\_create\_inventory (i think) - this  
file is the one that will actually update the database to create the  
specific table and its fields.
- you should be able to go to app\models\inventory.rb and add  
set\_table\_name ‘inventory’ to make it all work.

I may be wrong, but that is my understanding.

It seems that it ‘may’ be a restriction in AjaxScaffold (or perhaps it  
will work fine after the model is defined to use the table ‘inventory’)  
but it’s certainly not a problem with the way Rails works.

Cheers  
Mohit.

---

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [August 15, 2006, 10:03pm UTC](https://www.ruby-forum.com/t/try-creating-a-table-for-your-model/65039/6 "2006-08-15T22:03:44Z")

</div>

@Phlip:

The workflow that should be observed for creating a Rails application is

1. Create a Rails app (of course)

2. start with a blank database (no tables0

3. ruby script/generate model InventoryItems

4. edit the file db/migrate/001\_create\_inventory\_items.rb

5. Define your table definition using this file.

6. run ‘rake migrate’ to build the table in your database.

7. Test with console  
ruby script/console

8. Write unit tests using something similar to the console entries  
above.

9. Edit your app/models/inventory\_item.rb file and do any validations,  
etc

10. Run your tests again.

10 \*\* OPTIONAL \*\* ruby script/generate scaffold InventoryItem inventory  
11. ruby script/server and test in the browser.

Why InventoryItem? Because I just don’t like using inventories, and it  
makes  
more sence to me later when I say  
store :has\_many :inventory\_items

---

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [August 15, 2006, 8:42pm UTC](https://www.ruby-forum.com/t/try-creating-a-table-for-your-model/65039/7 "2006-08-15T20:42:29Z")

</div>

Daniel H. wrote:

> The table/model naming isn’t a “false” feature, but a feature 🙂 You don’t  
> have to create a view or rename the table, though your life will be made  
> easier if your table names are pluralized. If you want to use a table name  
> that Rails doesn’t expect, you can use “set\_table\_name ‘inventory’” in your  
> model class.

No I can’t. The model class doesn’t exist until I run generate, which  
won’t finish until I pluralize the table name.

Another reason why you will continue to field this FAQ is because, up  
until that error message (AND until dumping the log to see what the  
real problem was), there’s simply no way for the initiate to guess  
they are on-track. I couldn’t tell if I screwed up here, or long  
before, and I couldn’t tell if I was at the head of the error cascade.  
So even \>I\< had to ask, despite I have been using  
Model-View-Controller, and writing Web servers from scratch, since  
before Ruby existed…
