From: Josh Cheek Date: 2010-09-05T00:50:30+09:00 Subject: Re: ActiveRecord and incrementing the key --001485f9a7e2597d13048f70f6cd Content-Type: text/plain; charset=ISO-8859-1 On Sat, Sep 4, 2010 at 10:17 AM, Abder-Rahman Ali < abder.rahman.ali@gmail.com> wrote: > In "The Rails Way" book, the following is mentiond in Chapter > (6):Working with ActiveRecord > > "Also by convention, ActiveRecord will expect an id column to use as > primary key. It should be an integer and [[incrementing of the key > should be managed automatically by the database server when creating new > records]]." > > How does the database server manage the incrementing of the key? What is > meant here by the database server is what manages the incrementing of > the key? > > Is there an example that may make this point more clear. For example, > the following "database server" increments...... > > Thanks. > -- > Posted via http://www.ruby-forum.com/. > > If you're using migrations, then it will add this by default, unless you tell it not to (meaning don't worry, it will be there). I'd probably look at http://guides.rubyonrails.org/migrations.html as my first resource in that situation, though you'll want to check your version of AR against whatever they're using, they released AR 3 five days ago http://rubygems.org/gems/activerecord those guides were last updated on July 15th. You're probably fine, but just be aware of that if examples don't seem to be working. If you're not using migrations, then you'll want to do something like this http://github.com/JoshCheek/Play/blob/master/blackboardbot/create_database.rb CREATE TABLE IF NOT EXISTS posts ( id INTEGER PRIMARY KEY ASC AUTOINCREMENT, subject Text, body Text, author Text, message_board_id Integer ); The second line defines the id, and will depend on your database, for instance, I got the syntax for that one at http://www.sqlite.org/lang_createtable.html --001485f9a7e2597d13048f70f6cd--