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);
| SitePoint Sponsor |
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);



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 ;




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



I think it has to be like this:Originally Posted by Fenrir2
Code:create_table(:yourtable, :options => 'AUTO_INCREMENT=3') do |t| # create columns end
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