# default database schema and relationships

**URL:** <https://discuss.rubyonrails.org/t/default-database-schema-and-relationships/8627>\
**Category:** rubyonrails-talk\
**Created:** [February 13, 2007, 12:58am UTC](https://discuss.rubyonrails.org/t/default-database-schema-and-relationships/8627 "2007-02-13T00:58:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![arigold](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@arigold](https://discuss.rubyonrails.org/u/arigold)\
**Post date:** [February 13, 2007, 12:58am UTC](https://discuss.rubyonrails.org/t/default-database-schema-and-relationships/8627/1 "2007-02-13T00:58:26Z")

</div>

hi everyone..

i'm a high school teacher who wrote a webapp in PHP and MySQL for my curriculum.. i use it to keep attendance, take notes per student or class and keep track of activities. i would like to soup it up and have read both the pickax and version 2 of agile web dev...

now i'm starting to work and i'd like to rename columns and relationships in the database so that when i create rails functionality to work with the database i can use the same database. yep, i dont want to copy the data to a new database and have two apps and two databases but its live - im using it daily. i'd like to slowly move the functionality to the rails app and eventually just archive the PHP one. but before i do that i have to switch my primary keys to the rails defaults and the join tables and all that jazz to the rails defaults..

i'm not worried about the data because i back it up and if all else fails i'll just do the ol' INSERT INTO or UPDATE commands in terminal.

all that being said (phew) are the different defaults for rails in terms of column types (id type, etc) and singular plural conventions kept in one place somewhere? has anyone made a list? ive searched the web quite a bit and was going to start going through v2 of agile web dev but i thought i'd try an email before i got too into it..

sorry for the long background but i thought it best to be thorough..

thanks..~ari

---

<div class="post-metadata">

**Author:** ![Phlip](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@Phlip](https://discuss.rubyonrails.org/u/Phlip)\
**Post date:** [February 13, 2007, 5:06am UTC](https://discuss.rubyonrails.org/t/default-database-schema-and-relationships/8627/2 "2007-02-13T05:06:47Z")

</div>

arigold wrote:

> i'm a high school teacher

Don't you mean "i ARE a high school teacher"? 😉

> have read both the pickax and version 2 of agile web dev...

Grab /Rails Recipes/, by Chad Fowler, and hie thee hence to page 73, "Integrating with Legacy Databases". The shortest answer is you must start using all the defaults that you currently leave out of the ActiveRecord calls. Google for ActiveRecord::Base.set\_primary\_key or .table\_name\_prefix for a preview.

---

<div class="post-metadata">

**Author:** ![arigold](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@arigold](https://discuss.rubyonrails.org/u/arigold)\
**Post date:** [February 14, 2007, 12:34am UTC](https://discuss.rubyonrails.org/t/default-database-schema-and-relationships/8627/3 "2007-02-14T00:34:44Z")

</div>

thank you philip..

dont quite get the "i ARE a high school teacher" joke but maybe thats because i just got home and had back to back 10th and 9th graders. maybe, just maybe 14 - 16 year olds arent biologically able to be focused after 8 hours of school.. hmm.. ; )

i just might get that rails recipes book but from your short answer i dont think that it answers my question. it seems like you're looking to bend rails to the legacy database. i want to - yes its true - bend the legacy database to rails' defaults. i want to change the ID column from "student\_id" to "id". actually, ive done that one already.. im wondering what other things i'll need to change in the legacy database to make it comply with the rails defaults.

any ideas?

in any event, thanks for pointing that book out..

all the best..~ari

---

<div class="post-metadata">

**Author:** ![Andrew\_Stone](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Andrew\_Stone](https://discuss.rubyonrails.org/u/Andrew_Stone)\
**Post date:** [February 14, 2007, 12:46am UTC](https://discuss.rubyonrails.org/t/default-database-schema-and-relationships/8627/4 "2007-02-14T00:46:16Z")

</div>

> kept in one place somewhere? has anyone made a list? ive searched

I don’t know if there is a list, but if someone else knows, that would be a good resource to share. I would recommend using [api.rubyonrails.com](http://api.rubyonrails.com) and looking at the following relationships (listed in the lower left pane):

belongs\_to has\_and\_belongs\_to\_many has\_many has\_one

I think all give notes on database structure.

-andy

---

<div class="post-metadata">

**Author:** ![Phlip](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@Phlip](https://discuss.rubyonrails.org/u/Phlip)\
**Post date:** [February 14, 2007, 3:39pm UTC](https://discuss.rubyonrails.org/t/default-database-schema-and-relationships/8627/5 "2007-02-14T15:39:17Z")

</div>

arigold wrote:

> dont quite get the "i ARE a high school teacher" joke

You were permitting sloppy grammar...

> ...comply with the rails defaults...

Rails practices "Convention over Configuration". Those are not defaults they are conventions, and if you convene or configure Rails differently, it will obey.

Your best bet would be a combination of that chapter in /Rails Recipes/ and database migrations. Pick whichever is easiest, for each detail of non-compliance.

---

<div class="post-metadata">

**Author:** ![Andrew\_Vit1](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@Andrew\_Vit1](https://discuss.rubyonrails.org/u/Andrew_Vit1)\
**Post date:** [February 14, 2007, 4:42pm UTC](https://discuss.rubyonrails.org/t/default-database-schema-and-relationships/8627/6 "2007-02-14T16:42:02Z")

</div>

Here's a helpful blog post I found titled "making a web app rewrite work"

> **[making a web app rewrite work](https://blog.evanweaver.com/2007/02/01/making-a-web-app-rewrite-work/)**
>
> One of my friends was recently involved in a very large Rails rewrite project that failed pretty abjectly. Meanwhile, at CNET, we just deployed a total overhaul of a crufty old Rails app, replacing…

HTH, Andrew
