# How do I create a table for my model?

**URL:** <https://www.ruby-forum.com/t/how-do-i-create-a-table-for-my-model/104136>\
**Category:** Rails\
**Created:** [May 14, 2007, 5:52pm UTC](https://www.ruby-forum.com/t/how-do-i-create-a-table-for-my-model/104136 "2007-05-14T17:52:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [May 14, 2007, 5:52pm UTC](https://www.ruby-forum.com/t/how-do-i-create-a-table-for-my-model/104136/1 "2007-05-14T17:52:20Z")

</div>

I’m not sure what is meant by “create a table for the model” because the  
database has a table…they mean a different table?

[thufir@localhost dummy]$  
[thufir@localhost dummy]$  
[thufir@localhost dummy]$ ruby script/generate scaffold dummy  
exists app/controllers/  
exists app/helpers/  
exists app/views/dummies  
exists app/views/layouts/  
exists test/functional/  
dependency model  
exists app/models/  
exists test/unit/  
exists test/fixtures/  
identical app/models/dummy.rb  
identical test/unit/dummy\_test.rb  
identical test/fixtures/dummies.yml  
error Before updating scaffolding from new DB schema, try  
creating a table for your model (Dummy)  
[thufir@localhost dummy]$ ll  
total 116  
drwxrwxr-x 6 thufir thufir 4096 May 13 04:15 app  
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 components  
drwxrwxr-x 3 thufir thufir 4096 May 13 05:11 config  
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 db  
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 doc  
drwxrwxr-x 3 thufir thufir 4096 May 13 04:15 lib  
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 log  
drwxrwxr-x 5 thufir thufir 4096 May 13 04:15 public  
-rw-rw-r-- 1 thufir thufir 307 May 13 04:15 Rakefile  
-rw-rw-r-- 1 thufir thufir 8001 May 13 04:15 README  
drwxrwxr-x 4 thufir thufir 4096 May 13 04:15 script  
drwxrwxr-x 7 thufir thufir 4096 May 13 04:15 test  
drwxrwxr-x 6 thufir thufir 4096 May 13 04:15 tmp  
drwxrwxr-x 3 thufir thufir 4096 May 13 04:15 vendor  
[thufir@localhost dummy]$  
[thufir@localhost dummy]$  
[thufir@localhost dummy]$ cat config/database.yml

# MySQL (default setup). Versions 4.1 and 5.0 are recommended.

# 

# Install the MySQL driver:

# gem install mysql

# On MacOS X:

# gem install mysql – --include=/usr/local/lib

# On Windows:

# gem install mysql

# Choose the win32 build.

# Install MySQL and put its /bin directory on your path.

# 

# And be sure to use new-style password hashing:

# [http://dev.mysql.com/doc/refman/5.0/en/old-client.html](http://dev.mysql.com/doc/refman/5.0/en/old-client.html)

development:  
adapter: mysql  
database: dummy\_development  
username: feeds  
password: password  
socket: /var/lib/mysql/mysql.sock

# 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: dummy\_test  
username: feeds  
password: password  
socket: /var/lib/mysql/mysql.sock

production:  
adapter: mysql  
database: dummy\_production  
username: feeds  
password: password  
socket: /var/lib/mysql/mysql.sock  
[thufir@localhost dummy]$  
[thufir@localhost dummy]$  
[thufir@localhost dummy]$ mysql -u feeds -p  
Enter password:  
Welcome to the MySQL monitor. Commands end with ; or \g.  
Your MySQL connection id is 37 to server version: 5.0.27

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql\>  
mysql\> show databases;  
±-------------------+  
| Database |  
±-------------------+  
| information\_schema |  
| dummy |  
| dummy\_development |  
| feeds |  
| mysql |  
| test |  
±-------------------+  
6 rows in set (0.00 sec)

mysql\> use dummy;  
Reading table information for completion of table and column  
names  
You can turn off this feature to get a quicker startup with -A

Database changed  
mysql\> describe dummy;  
ERROR 1146 (42S02): Table ‘dummy.dummy’ doesn’t exist  
mysql\> show tables;  
±----------------+  
| Tables\_in\_dummy |  
±----------------+  
| px\_feeds |  
±----------------+  
1 row in set (0.00 sec)

mysql\> describe px\_feeds;  
±------------±-------------±-----±----±--------  
±---------------+  
| Field | Type | Null | Key | Default |  
Extra |  
±------------±-------------±-----±----±--------  
±---------------+  
| id | int(11) | NO | PRI | NULL |  
auto\_increment |  
| url | varchar(250) | NO | |  
| |  
| title | varchar(250) | NO | |  
| |  
| link | varchar(250) | YES | | NULL  
| |  
| description | varchar(250) | YES | | NULL  
| |  
±------------±-------------±-----±----±--------  
±---------------+  
5 rows in set (0.01 sec)

mysql\>  
mysql\> quit  
Bye  
[thufir@localhost dummy]$  
[thufir@localhost dummy]$  
[thufir@localhost dummy]$ cat /etc/fedora-release  
Fedora Core release 6 (Zod)  
[thufir@localhost dummy]$  
[thufir@localhost dummy]$ date  
Mon May 14 16:46:54 BST 2007  
[thufir@localhost dummy]$  
[thufir@localhost dummy]$

thanks,

Thufir

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [May 14, 2007, 6:04pm UTC](https://www.ruby-forum.com/t/how-do-i-create-a-table-for-my-model/104136/2 "2007-05-14T18:04:21Z")

</div>

On May 14, 2007, at 11:49 AM, Thufir wrote:

> I’m not sure what is meant by “create a table for the model”  
> because the  
> database has a table…they mean a different table?

From your output it looks like you have a database named ‘dummy’  
containing a single table named ‘px\_feeds’. The scaffold generator  
can automatically create a PxFeed model based on the px\_feeds table,  
but you’re (implicitly) telling it to look for a ‘dummies’ table to  
create a Dummy model and DummiesController controller (‘dummy’ -\>  
‘dummies’, assuming this falls under the general pluralization rules).

-faisal

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [May 14, 2007, 9:31pm UTC](https://www.ruby-forum.com/t/how-do-i-create-a-table-for-my-model/104136/3 "2007-05-14T21:31:54Z")

</div>

Rails assumes, that the table for a model called “dummy” is called  
“dummies”, the table for a “user” model would be “users” etc. - unless  
you’ve configured Rails differently. That’s one of Rails’ main  
priciples, convention over configuration. I’d recommend a book called  
“Agile web development with Rails” - the first part walks you through  
the development of a simple shop app, which will address 90% of the  
problems you’ll come across eventually, the second is a great  
reference when you start building your own apps (and it also includes  
the basics of Ruby, so don’t worry about that). It’s definitely worth  
it - and look for the 2nd edition.  
[http://pragmaticprogrammer.com/titles/rails](http://pragmaticprogrammer.com/titles/rails)

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [May 15, 2007, 12:35am UTC](https://www.ruby-forum.com/t/how-do-i-create-a-table-for-my-model/104136/4 "2007-05-15T00:35:29Z")

</div>

On May 14, 9:01 am, Faisal N Jawdat [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
[…]

> From your output it looks like you have a database named ‘dummy’  
> containing a single table named ‘px\_feeds’. The scaffold generator  
> can automatically create a PxFeed model based on the px\_feeds table,  
> but you’re (implicitly) telling it to look for a ‘dummies’ table to  
> create a Dummy model and DummiesController controller (‘dummy’ →   
> ‘dummies’, assuming this falls under the general pluralization rules).
> 
> -faisal

Aha, thanks. Long term I’ll have to muck with the the configuration  
because the feed-on-feeds database is setup how it’s setup, ruby will  
have to work around it ☹

-Thufir

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [May 16, 2007, 3:23am UTC](https://www.ruby-forum.com/t/how-do-i-create-a-table-for-my-model/104136/5 "2007-05-16T03:23:12Z")

</div>

On May 14, 8:30 pm, tjanson [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Rails assumes, that the table for a model called “dummy” is called  
> “dummies”, the table for a “user” model would be “users” etc. - unless  
> you’ve configured Rails differently.  
> […]

Have I not done so?

[thufir@localhost dummy]$  
[thufir@localhost dummy]$ ruby script/generate scaffold dummy  
exists app/controllers/  
exists app/helpers/  
exists app/views/dummies  
exists app/views/layouts/  
exists test/functional/  
dependency model  
exists app/models/  
exists test/unit/  
exists test/fixtures/  
identical app/models/dummy.rb  
identical test/unit/dummy\_test.rb  
identical test/fixtures/dummies.yml  
error Before updating scaffolding from new DB schema, try  
creating a table for your model (Dummy)  
[thufir@localhost dummy]$  
[thufir@localhost dummy]$ pwd  
/home/thufir/dummy  
[thufir@localhost dummy]$ ll  
total 116  
drwxrwxr-x 6 thufir thufir 4096 May 13 04:15 app  
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 components  
drwxrwxr-x 3 thufir thufir 4096 May 13 05:11 config  
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 db  
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 doc  
drwxrwxr-x 3 thufir thufir 4096 May 13 04:15 lib  
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 log  
drwxrwxr-x 5 thufir thufir 4096 May 13 04:15 public  
-rw-rw-r-- 1 thufir thufir 307 May 13 04:15 Rakefile  
-rw-rw-r-- 1 thufir thufir 8001 May 13 04:15 README  
drwxrwxr-x 4 thufir thufir 4096 May 13 04:15 script  
drwxrwxr-x 7 thufir thufir 4096 May 13 04:15 test  
drwxrwxr-x 6 thufir thufir 4096 May 13 04:15 tmp  
drwxrwxr-x 3 thufir thufir 4096 May 13 04:15 vendor  
[thufir@localhost dummy]$  
[thufir@localhost dummy]$ mysql -u feeds -p  
Enter password:  
Welcome to the MySQL monitor. Commands end with ; or \g.  
Your MySQL connection id is 32 to server version: 5.0.27

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql\>  
mysql\> use dummy;  
Reading table information for completion of table and column names  
You can turn off this feature to get a quicker startup with -A

Database changed  
mysql\> show tables;  
±----------------+  
| Tables\_in\_dummy |  
±----------------+  
| dummies |  
±----------------+  
1 row in set (0.00 sec)

mysql\> quit  
Bye  
[thufir@localhost dummy]$  
[thufir@localhost dummy]$ cat config/database.yml

# MySQL (default setup). Versions 4.1 and 5.0 are recommended.

# 

# Install the MySQL driver:

# gem install mysql

# On MacOS X:

# gem install mysql – --include=/usr/local/lib

# On Windows:

# gem install mysql

# Choose the win32 build.

# Install MySQL and put its /bin directory on your path.

# 

# And be sure to use new-style password hashing:

# [http://dev.mysql.com/doc/refman/5.0/en/old-client.html](http://dev.mysql.com/doc/refman/5.0/en/old-client.html)

development:  
adapter: mysql  
database: dummy\_development  
username: feeds  
password: password  
socket: /var/lib/mysql/mysql.sock

# 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: dummy\_test  
username: feeds  
password: password  
socket: /var/lib/mysql/mysql.sock

production:  
adapter: mysql  
database: dummy\_production  
username: feeds  
password: password  
socket: /var/lib/mysql/mysql.sock  
[thufir@localhost dummy]$  
[thufir@localhost dummy]$ cat /etc/fedora-release  
Fedora Core release 6 (Zod)  
[thufir@localhost dummy]$  
[thufir@localhost dummy]$ date  
Wed May 16 02:19:51 BST 2007  
[thufir@localhost dummy]$

thanks,

Thufir

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [May 16, 2007, 4:39am UTC](https://www.ruby-forum.com/t/how-do-i-create-a-table-for-my-model/104136/6 "2007-05-16T04:39:20Z")

</div>

It looks like your database is called “dummy”,

> mysql\> use dummy;

but your YAML file (and Rails convention) has “dummy\_development”,  
etc.

> development:  
> adapter: mysql  
> database: dummy\_development

Is that your problem? (Sorry, didn’t see or pay attention to your  
initial post)

-Rob

On May 15, 2007, at 9:22 PM, Thufir wrote:

> ```
> exists test/unit/
> 
> ```
> 
> total 116  
> drwxrwxr-x 4 thufir thufir 4096 May 13 04:15 script
> 
> | dummies |
> 
> # gem install mysql
> 
> adapter: mysql  
> database: dummy\_test  
> [thufir@localhost dummy]$  
> Thufir  
> Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
> removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [May 16, 2007, 7:20am UTC](https://www.ruby-forum.com/t/how-do-i-create-a-table-for-my-model/104136/7 "2007-05-16T07:20:30Z")

</div>

On May 16, 3:38 am, Rob B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> It looks like your database is called “dummy”,
> 
> > mysql\> use dummy;
> 
> but your YAML file (and Rails convention) has “dummy\_development”,  
> etc.  
> […]

This I’m unclear on. The database should be called dummy or  
dummy\_development ? change the YAML to match the database or the  
database to match the YAML? If the mountain won’t come to mohammed,  
then…

I was thinking that ruby would automagically figure out the  
\*\_development in keeping with its automagically figuring out dummy and  
its plural dummies.

-Thufir

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [May 16, 2007, 7:17am UTC](https://www.ruby-forum.com/t/how-do-i-create-a-table-for-my-model/104136/8 "2007-05-16T07:17:30Z")

</div>

thanks, one step closer 🙂

now I’m looking into how to display a “SELECT \* FROM dummies” query.

[thufir@localhost dummy]$  
[thufir@localhost dummy]$  
[thufir@localhost dummy]$ pwd  
/home/thufir/dummy  
[thufir@localhost dummy]$  
[thufir@localhost dummy]$ ll  
total 116  
drwxrwxr-x 6 thufir thufir 4096 May 13 04:15 app  
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 components  
drwxrwxr-x 3 thufir thufir 4096 May 16 06:06 config  
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 db  
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 doc  
drwxrwxr-x 3 thufir thufir 4096 May 13 04:15 lib  
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 log  
drwxrwxr-x 5 thufir thufir 4096 May 13 04:15 public  
-rw-rw-r-- 1 thufir thufir 307 May 13 04:15 Rakefile  
-rw-rw-r-- 1 thufir thufir 8001 May 13 04:15 README  
drwxrwxr-x 4 thufir thufir 4096 May 13 04:15 script  
drwxrwxr-x 7 thufir thufir 4096 May 13 04:15 test  
drwxrwxr-x 6 thufir thufir 4096 May 13 04:15 tmp  
drwxrwxr-x 3 thufir thufir 4096 May 13 04:15 vendor  
[thufir@localhost dummy]$  
[thufir@localhost dummy]$ cat config/database.yml

# MySQL (default setup). Versions 4.1 and 5.0 are recommended.

# 

# Install the MySQL driver:

# gem install mysql

# On MacOS X:

# gem install mysql – --include=/usr/local/lib

# On Windows:

# gem install mysql

# Choose the win32 build.

# Install MySQL and put its /bin directory on your path.

# 

# And be sure to use new-style password hashing:

# [http://dev.mysql.com/doc/refman/5.0/en/old-client.html](http://dev.mysql.com/doc/refman/5.0/en/old-client.html)

development:  
adapter: mysql  
database: dummy  
username: feeds  
password: password  
socket: /var/lib/mysql/mysql.sock

# 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: dummy  
username: feeds  
password: password  
socket: /var/lib/mysql/mysql.sock

production:  
adapter: mysql  
database: dummy  
username: feeds  
password: password  
socket: /var/lib/mysql/mysql.sock  
[thufir@localhost dummy]$  
[thufir@localhost dummy]$ ruby script/generate scaffold dummy  
exists app/controllers/  
exists app/helpers/  
exists app/views/dummies  
exists app/views/layouts/  
exists test/functional/  
dependency model  
exists app/models/  
exists test/unit/  
exists test/fixtures/  
identical app/models/dummy.rb  
identical test/unit/dummy\_test.rb  
identical test/fixtures/dummies.yml  
identical app/views/dummies/\_form.rhtml  
identical app/views/dummies/list.rhtml  
identical app/views/dummies/show.rhtml  
identical app/views/dummies/new.rhtml  
identical app/views/dummies/edit.rhtml  
identical app/controllers/dummies\_controller.rb  
identical test/functional/dummies\_controller\_test.rb  
identical app/helpers/dummies\_helper.rb  
identical app/views/layouts/dummies.rhtml  
identical public/stylesheets/scaffold.css  
[thufir@localhost dummy]$  
[thufir@localhost dummy]$ ruby script/server  
=\> Booting WEBrick…  
=\> Rails application started on [http://0.0.0.0:3000](http://0.0.0.0:3000)  
=\> Ctrl-C to shutdown server; call with --help for options  
[2007-05-16 06:13:09] INFO WEBrick 1.3.1  
[2007-05-16 06:13:09] INFO ruby 1.8.5 (2007-03-13) [i386-linux]  
[2007-05-16 06:13:09] INFO WEBrick::HTTPServer#start: pid=3786  
port=3000  
127.0.0.1 - - [16/May/2007:06:13:15 BST] “GET / HTTP/1.1” 304 0

- → /  
127.0.0.1 - - [16/May/2007:06:13:16 BST] “GET /javascripts/  
prototype.js HTTP/1.1” 304 0  
[http://localhost:3000/](http://localhost:3000/) → /javascripts/prototype.js  
127.0.0.1 - - [16/May/2007:06:13:16 BST] “GET /javascripts/effects.js  
HTTP/1.1” 304 0  
[http://localhost:3000/](http://localhost:3000/) → /javascripts/effects.js  
127.0.0.1 - - [16/May/2007:06:13:16 BST] “GET /images/rails.png HTTP/  
1.1” 304 0  
[http://localhost:3000/](http://localhost:3000/) → /images/rails.png  
[2007-05-16 06:13:23] INFO going to shutdown …  
[2007-05-16 06:13:23] INFO WEBrick::HTTPServer#start done.  
[thufir@localhost dummy]$  
[thufir@localhost dummy]$ date  
Wed May 16 06:13:26 BST 2007  
[thufir@localhost dummy]$  
[thufir@localhost dummy]$

thanks,

Thufir
