Hi. I get some strange results when using rename_column on a primary key in a migration. It seems like the migration script removes the auto-increment property if you rename a column. This is a minimal example. create_table :foo, :primary_key => :foo_id do |t| t.column "name", :string end # renaming the primary key makes auto-increment disappear. rename_column :foo, :foo_id, :bar_id Is this a known problem, any beautiful solution available? Maybe use change_column instead? Best regards, Tobias Nurmiranta --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Tobias Numiranta wrote:> create_table :foo, :primary_key => :foo_id do |t| > t.column "name", :string > end > > # renaming the primary key makes auto-increment disappear. > rename_column :foo, :foo_id, :bar_idWhat RDBMS are you using? Can you show what the table schema looks like (as reported by the rdbms) before and after the change? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Sure. I''m using Mysql. Using mysqldump before and after I get: before: CREATE TABLE `foo` ( `foo_id` int(11) NOT NULL auto_increment, `name` varchar(255) default NULL, PRIMARY KEY (`foo_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; after: CREATE TABLE `foo` ( `bar_id` int(11) NOT NULL default ''0'', `name` varchar(255) default NULL, PRIMARY KEY (`bar_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; Have a nice day, T On Oct 31, 3:19 pm, "Phrogz" <g...-XtLdkLkwz3ZWk0Htik3J/w@public.gmane.org> wrote:> Tobias Numiranta wrote: > > create_table :foo, :primary_key => :foo_id do |t| > > t.column "name", :string > > end > > > # renaming the primary key makes auto-increment disappear. > > rename_column :foo, :foo_id, :bar_idWhat RDBMS are you using? Can you show what the table schema looks like > (as reported by the rdbms) before and after the change?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Tobias Numiranta wrote:> Sure. I''m using Mysql. Using mysqldump before and after I get: > > before: > > CREATE TABLE `foo` ( > `foo_id` int(11) NOT NULL auto_increment, > `name` varchar(255) default NULL, > PRIMARY KEY (`foo_id`) > ) ENGINE=InnoDB DEFAULT CHARSET=latin1; > > after: > > CREATE TABLE `foo` ( > `bar_id` int(11) NOT NULL default ''0'', > `name` varchar(255) default NULL, > PRIMARY KEY (`bar_id`) > ) ENGINE=InnoDB DEFAULT CHARSET=latin1;Interesting. I don''t use MySQL. What do the logs show as the SQL being issued to MySQL for the change_column migration? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On Oct 31, 6:14 pm, "Phrogz" <g...-XtLdkLkwz3ZWk0Htik3J/w@public.gmane.org> wrote:> Tobias Numiranta wrote: > > Sure. I''m using Mysql. Using mysqldump before and after I get: > > > before: > > > CREATE TABLE `foo` ( > > `foo_id` int(11) NOT NULL auto_increment, > > `name` varchar(255) default NULL, > > PRIMARY KEY (`foo_id`) > > ) ENGINE=InnoDB DEFAULT CHARSET=latin1; > > > after: > > > CREATE TABLE `foo` ( > > `bar_id` int(11) NOT NULL default ''0'', > > `name` varchar(255) default NULL, > > PRIMARY KEY (`bar_id`) > > ) ENGINE=InnoDB DEFAULT CHARSET=latin1;Interesting. I don''t use MySQL. What do the logs show as the SQL being > issued to MySQL for the change_column migration?Hi. This is the issued SQL: -- create_table(:foo, {:primary_key=>:foo_id}) CREATE TABLE foo (`foo_id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255)) ENGINE=InnoDB -- rename_column(:foo, :foo_id, :bar_id) SHOW COLUMNS FROM foo LIKE ''foo_id'' ALTER TABLE foo CHANGE foo_id bar_id int(11) Maybe the alter table command need to specify auto_increment, but rails doesn''t do so? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---