SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Dec 2005
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Rails: Setting initial primary key value

    Hi, I'm new to ruby and rails. I'm trying to build db/schema.rb but I'm not sure how to get the default id column to start counting at a number higher than 0. Is there a way to a db agnostic equiv. of (pgsql):

    SELECT setval('Users_UID_seq', 2000);

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When you are creating a table in mySQL, at the end just do AUTO_INCREMENT=x where x is the next number you want to have. Example:
    Code:
    CREATE TABLE `categories` (
      `cat_ID` bigint(20) NOT NULL auto_increment,
      `cat_name` varchar(55) NOT NULL default '',
      `category_description` longtext NOT NULL,
      PRIMARY KEY  (`cat_ID`),
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

  3. #3
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This might work:

    Code:
    create_table(:yourtable, 'AUTO_INCREMENT=3') do |t|
      # create columns
    end

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Fenrir2
    This might work:

    Code:
    create_table(:yourtable, 'AUTO_INCREMENT=3') do |t|
       # create columns
     end
    I think it has to be like this:
    Code:
    create_table(:yourtable, :options => 'AUTO_INCREMENT=3') do |t|
       # create columns
     end

  5. #5
    SitePoint Member
    Join Date
    Dec 2005
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the replies. I assume that only works for MySQL? In practice, for Active Records and Migrations, should I only attempt to support one database type?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •