Good day! I''ve recently started to develop under rails. I have a migration that should create a table, and I want the primary key id to be not standard auto-incrementing integer but explicitly given string. I have language codes and language native names in the table so I don''t want either to keep that meaningless integer id in the db or to have it appear in the uri. The first question is, does this seriously compromise rails'' magic? Will scaffolding work? The second question is, the migration doesn''t work as I suppose it should. It is class CreateLanguages < ActiveRecord::Migration def self.up create_table :languages, {:id=>false} do |t| t.column :id, :string, {:limit=>12} t.column :name, :string, {:limit=>60, :null=>false} t.primary_key :id end end But what is created is like the last line is ignored `id` varchar(12) default NULL, `name` varchar(60) NOT NULL I''m using MySQL 5.0 Could you please clarify this behaviour and make a suggestion? Your sincerely, Damian/Three-eyed Fish --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
augustlilleaas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jan-18 11:58 UTC
Re: Non-standard primary key column
Yes, this seriously compromises rails'' magic. It expects an auto incremented integer. I''m not sure about the t.primary_key method, but this should work: def self.up execute "ALTER TABLE languages ADD id string(12) DEFAULT NULL PRIMARY KEY" end A bit not-so-clean, though. On Jan 18, 12:20 pm, Damian Terentyev <threeeyedf...-HPQIj1OAFZMvJsYlp49lxw@public.gmane.org> wrote:> Good day! > I''ve recently started to develop under rails. > I have a migration that should create a table, and I want the primary > key id to be not standard auto-incrementing integer but explicitly > given string. > I have language codes and language native names in the table so I don''t > want either to keep that meaningless integer id in the db or to have it > appear in the uri. > The first question is, does this seriously compromise rails'' magic? > Will scaffolding work? > The second question is, the migration doesn''t work as I suppose it > should. > It is > > class CreateLanguages < ActiveRecord::Migration > def self.up > create_table :languages, {:id=>false} do |t| > t.column :id, :string, {:limit=>12} > t.column :name, :string, {:limit=>60, :null=>false} > t.primary_key :id > end > end > > But what is created is like the last line is ignored > > `id` varchar(12) default NULL, > `name` varchar(60) NOT NULL > > I''m using MySQL 5.0 > > Could you please clarify this behaviour and make a suggestion? > > Your sincerely, > Damian/Three-eyed Fish--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 18, 2007, at 14:58, augustlilleaas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> Yes, this seriously compromises rails'' magic. It expects an auto > incremented integer.Thank you! I hope I will change my thinking and implement my system in a more railish way. Your sincerely, Damian/Three-eyed Fish --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---