Hi, Is there a way when using scaffolding to name a primary key like tablename_id instead of the default id? Thanks, Kostas --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You could do this: script/generate scaffold player player_id:primary_key name:string which generates a migration like this class CreatePlayers < ActiveRecord::Migration def self.up create_table :players do |t| t.primary_key :player_id t.string :name t.timestamps end end def self.down drop_table :players end end Regards, Craig --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks for the answer. I run: script/generate scaffold reservation reservation_id:primary_key name:string followed by rake db:migrate and I get the following error: == 20080830212120 CreateReservations: migrating ==============================-- create_table(:reservations) rake aborted! Mysql::Error: Incorrect table definition; there can be only one auto column and it must be defined as a key: CREATE TABLE `reservations` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `reservation_id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `reservation_name` varchar(255) DEFAULT NULL NULL, `created_at` datetime DEFAULT NULL NULL, `updated_at` datetime DEFAULT NULL NULL) ENGINE=InnoDB Apparently it tries to create two primary keys and fails. Kostas On Aug 30, 9:31 pm, "Craig Demyanovich" <cdemyanov...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You could do this: > > script/generate scaffold player player_id:primary_key name:string > > which generates a migration like this > > class CreatePlayers < ActiveRecord::Migration > def self.up > create_table :players do |t| > t.primary_key :player_id > t.string :name > > t.timestamps > end > end > > def self.down > drop_table :players > end > end > > Regards, > Craig--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 30 Aug 2008, at 22:23, samson78 wrote:> > Thanks for the answer. I run: > script/generate scaffold reservation reservation_id:primary_key > name:string >you need create_table :players, :id => false do |t| ... so that rails doesn''t try to create its primary key as well as your own. Fred> followed by > > rake db:migrate > > and I get the following error: > > == 20080830212120 CreateReservations: migrating > ==============================> -- create_table(:reservations) > rake aborted! > Mysql::Error: Incorrect table definition; there can be only one auto > column and it must be defined as a key: CREATE TABLE `reservations` > (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, > `reservation_id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, > `reservation_name` varchar(255) DEFAULT NULL NULL, `created_at` > datetime DEFAULT NULL NULL, `updated_at` datetime DEFAULT NULL NULL) > ENGINE=InnoDB > > Apparently it tries to create two primary keys and fails. > > Kostas > > > > On Aug 30, 9:31 pm, "Craig Demyanovich" <cdemyanov...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> You could do this: >> >> script/generate scaffold player player_id:primary_key name:string >> >> which generates a migration like this >> >> class CreatePlayers < ActiveRecord::Migration >> def self.up >> create_table :players do |t| >> t.primary_key :player_id >> t.string :name >> >> t.timestamps >> end >> end >> >> def self.down >> drop_table :players >> end >> end >> >> Regards, >> Craig > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks for the answer. I did that and the migration completed fine. Bit when I am trying to view the site it doesn''t show the edit, show, destroy links, but only the "new" one. And the Create new doesn''t work. Kostas On Aug 30, 10:33 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 30 Aug 2008, at 22:23, samson78 wrote: > > > > > Thanks for the answer. I run: > > script/generate scaffold reservation reservation_id:primary_key > > name:string > > you need create_table :players, :id => false do |t| ... > > so that rails doesn''t try to create its primary key as well as your own. > > Fred > > > followed by > > > rake db:migrate > > > and I get the following error: > > > == 20080830212120 CreateReservations: migrating > > ==============================> > -- create_table(:reservations) > > rake aborted! > > Mysql::Error: Incorrect table definition; there can be only one auto > > column and it must be defined as a key: CREATE TABLE `reservations` > > (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, > > `reservation_id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, > > `reservation_name` varchar(255) DEFAULT NULL NULL, `created_at` > > datetime DEFAULT NULL NULL, `updated_at` datetime DEFAULT NULL NULL) > > ENGINE=InnoDB > > > Apparently it tries to create two primary keys and fails. > > > Kostas > > > On Aug 30, 9:31 pm, "Craig Demyanovich" <cdemyanov...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> You could do this: > > >> script/generate scaffold player player_id:primary_key name:string > > >> which generates a migration like this > > >> class CreatePlayers < ActiveRecord::Migration > >> def self.up > >> create_table :players do |t| > >> t.primary_key :player_id > >> t.string :name > > >> t.timestamps > >> end > >> end > > >> def self.down > >> drop_table :players > >> end > >> end > > >> Regards, > >> Craig--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 30 Aug 2008, at 23:01, samson78 wrote:> > Thanks for the answer. > I did that and the migration completed fine. > Bit when I am trying to view the site it doesn''t show the edit, show, > destroy links, but only the "new" one. And the Create new doesn''t > work.have you got set_primary_key in your model ? Fred> > > Kostas > > On Aug 30, 10:33 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On 30 Aug 2008, at 22:23, samson78 wrote: >> >> >> >>> Thanks for the answer. I run: >>> script/generate scaffold reservation reservation_id:primary_key >>> name:string >> >> you need create_table :players, :id => false do |t| ... >> >> so that rails doesn''t try to create its primary key as well as your >> own. >> >> Fred >> >>> followed by >> >>> rake db:migrate >> >>> and I get the following error: >> >>> == 20080830212120 CreateReservations: migrating >>> ==============================>>> -- create_table(:reservations) >>> rake aborted! >>> Mysql::Error: Incorrect table definition; there can be only one auto >>> column and it must be defined as a key: CREATE TABLE `reservations` >>> (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, >>> `reservation_id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, >>> `reservation_name` varchar(255) DEFAULT NULL NULL, `created_at` >>> datetime DEFAULT NULL NULL, `updated_at` datetime DEFAULT NULL NULL) >>> ENGINE=InnoDB >> >>> Apparently it tries to create two primary keys and fails. >> >>> Kostas >> >>> On Aug 30, 9:31 pm, "Craig Demyanovich" <cdemyanov...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >>> wrote: >>>> You could do this: >> >>>> script/generate scaffold player player_id:primary_key name:string >> >>>> which generates a migration like this >> >>>> class CreatePlayers < ActiveRecord::Migration >>>> def self.up >>>> create_table :players do |t| >>>> t.primary_key :player_id >>>> t.string :name >> >>>> t.timestamps >>>> end >>>> end >> >>>> def self.down >>>> drop_table :players >>>> end >>>> end >> >>>> Regards, >>>> Craig > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The whole thing seems that has a problem with: 1)The params:id in the controller do I leave it as :id or do I write the new primary key, e.g. :reseravations_id 2)in the routes.rb map.connect '':controller/:action/:id'' map.connect '':controller/:action/:id.:format'' It cannot get route as it searches for :id Kostas On Aug 30, 10:33 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 30 Aug 2008, at 22:23, samson78 wrote: > > > > > Thanks for the answer. I run: > > script/generate scaffold reservation reservation_id:primary_key > > name:string > > you need create_table :players, :id => false do |t| ... > > so that rails doesn''t try to create its primary key as well as your own. > > Fred > > > followed by > > > rake db:migrate > > > and I get the following error: > > > == 20080830212120 CreateReservations: migrating > > ==============================> > -- create_table(:reservations) > > rake aborted! > > Mysql::Error: Incorrect table definition; there can be only one auto > > column and it must be defined as a key: CREATE TABLE `reservations` > > (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, > > `reservation_id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, > > `reservation_name` varchar(255) DEFAULT NULL NULL, `created_at` > > datetime DEFAULT NULL NULL, `updated_at` datetime DEFAULT NULL NULL) > > ENGINE=InnoDB > > > Apparently it tries to create two primary keys and fails. > > > Kostas > > > On Aug 30, 9:31 pm, "Craig Demyanovich" <cdemyanov...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> You could do this: > > >> script/generate scaffold player player_id:primary_key name:string > > >> which generates a migration like this > > >> class CreatePlayers < ActiveRecord::Migration > >> def self.up > >> create_table :players do |t| > >> t.primary_key :player_id > >> t.string :name > > >> t.timestamps > >> end > >> end > > >> def self.down > >> drop_table :players > >> end > >> end > > >> Regards, > >> Craig--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 30 Aug 2008, at 23:15, samson78 wrote:> > The whole thing seems that has a problem with: > > 1)The params:id in the controller > do I leave it as :id or do I write the new primary key, > e.g. :reseravations_id >should be able to leave it as :id - the primary key is always available as id (ie the id method always exists and will return the correct value) Fred> 2)in the routes.rb > > map.connect '':controller/:action/:id'' > map.connect '':controller/:action/:id.:format'' > > It cannot get route as it searches for :id> > > Kostas > > On Aug 30, 10:33 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On 30 Aug 2008, at 22:23, samson78 wrote: >> >> >> >>> Thanks for the answer. I run: >>> script/generate scaffold reservation reservation_id:primary_key >>> name:string >> >> you need create_table :players, :id => false do |t| ... >> >> so that rails doesn''t try to create its primary key as well as your >> own. >> >> Fred >> >>> followed by >> >>> rake db:migrate >> >>> and I get the following error: >> >>> == 20080830212120 CreateReservations: migrating >>> ==============================>>> -- create_table(:reservations) >>> rake aborted! >>> Mysql::Error: Incorrect table definition; there can be only one auto >>> column and it must be defined as a key: CREATE TABLE `reservations` >>> (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, >>> `reservation_id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, >>> `reservation_name` varchar(255) DEFAULT NULL NULL, `created_at` >>> datetime DEFAULT NULL NULL, `updated_at` datetime DEFAULT NULL NULL) >>> ENGINE=InnoDB >> >>> Apparently it tries to create two primary keys and fails. >> >>> Kostas >> >>> On Aug 30, 9:31 pm, "Craig Demyanovich" <cdemyanov...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >>> wrote: >>>> You could do this: >> >>>> script/generate scaffold player player_id:primary_key name:string >> >>>> which generates a migration like this >> >>>> class CreatePlayers < ActiveRecord::Migration >>>> def self.up >>>> create_table :players do |t| >>>> t.primary_key :player_id >>>> t.string :name >> >>>> t.timestamps >>>> end >>>> end >> >>>> def self.down >>>> drop_table :players >>>> end >>>> end >> >>>> Regards, >>>> Craig > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Yes, the primary key is set when I use reservation_id:primary key when calling the generate script After db:migrate it shows as primary key on the database. Kostas On Aug 30, 11:38 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 30 Aug 2008, at 23:15, samson78 wrote: > > > > > The whole thing seems that has a problem with: > > > 1)The params:id in the controller > > do I leave it as :id or do I write the new primary key, > > e.g. :reseravations_id > > should be able to leave it as :id - the primary key is always > available as id (ie the id method always exists and will return the > correct value) > > Fred > > > 2)in the routes.rb > > > map.connect '':controller/:action/:id'' > > map.connect '':controller/:action/:id.:format'' > > > It cannot get route as it searches for :id > > > Kostas > > > On Aug 30, 10:33 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> On 30 Aug 2008, at 22:23, samson78 wrote: > > >>> Thanks for the answer. I run: > >>> script/generate scaffold reservation reservation_id:primary_key > >>> name:string > > >> you need create_table :players, :id => false do |t| ... > > >> so that rails doesn''t try to create its primary key as well as your > >> own. > > >> Fred > > >>> followed by > > >>> rake db:migrate > > >>> and I get the following error: > > >>> == 20080830212120 CreateReservations: migrating > >>> ==============================> >>> -- create_table(:reservations) > >>> rake aborted! > >>> Mysql::Error: Incorrect table definition; there can be only one auto > >>> column and it must be defined as a key: CREATE TABLE `reservations` > >>> (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, > >>> `reservation_id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, > >>> `reservation_name` varchar(255) DEFAULT NULL NULL, `created_at` > >>> datetime DEFAULT NULL NULL, `updated_at` datetime DEFAULT NULL NULL) > >>> ENGINE=InnoDB > > >>> Apparently it tries to create two primary keys and fails. > > >>> Kostas > > >>> On Aug 30, 9:31 pm, "Craig Demyanovich" <cdemyanov...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >>> wrote: > >>>> You could do this: > > >>>> script/generate scaffold player player_id:primary_key name:string > > >>>> which generates a migration like this > > >>>> class CreatePlayers < ActiveRecord::Migration > >>>> def self.up > >>>> create_table :players do |t| > >>>> t.primary_key :player_id > >>>> t.string :name > > >>>> t.timestamps > >>>> end > >>>> end > > >>>> def self.down > >>>> drop_table :players > >>>> end > >>>> end > > >>>> Regards, > >>>> Craig--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Out of sheer curiosity, what''s the compelling reason to ditch Rails'' convention and change the primary key if you''re still using scaffolding? RSL On Sat, Aug 30, 2008 at 6:54 PM, samson78 <nemea-ee4meeAH724@public.gmane.org> wrote:> > Yes, the primary key is set when I use reservation_id:primary key when > calling the generate script > After db:migrate it shows as primary key on the database. > > Kostas > > On Aug 30, 11:38 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On 30 Aug 2008, at 23:15, samson78 wrote: >> >> >> >> > The whole thing seems that has a problem with: >> >> > 1)The params:id in the controller >> > do I leave it as :id or do I write the new primary key, >> > e.g. :reseravations_id >> >> should be able to leave it as :id - the primary key is always >> available as id (ie the id method always exists and will return the >> correct value) >> >> Fred >> >> > 2)in the routes.rb >> >> > map.connect '':controller/:action/:id'' >> > map.connect '':controller/:action/:id.:format'' >> >> > It cannot get route as it searches for :id >> >> > Kostas >> >> > On Aug 30, 10:33 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> > wrote: >> >> On 30 Aug 2008, at 22:23, samson78 wrote: >> >> >>> Thanks for the answer. I run: >> >>> script/generate scaffold reservation reservation_id:primary_key >> >>> name:string >> >> >> you need create_table :players, :id => false do |t| ... >> >> >> so that rails doesn''t try to create its primary key as well as your >> >> own. >> >> >> Fred >> >> >>> followed by >> >> >>> rake db:migrate >> >> >>> and I get the following error: >> >> >>> == 20080830212120 CreateReservations: migrating >> >>> ==============================>> >>> -- create_table(:reservations) >> >>> rake aborted! >> >>> Mysql::Error: Incorrect table definition; there can be only one auto >> >>> column and it must be defined as a key: CREATE TABLE `reservations` >> >>> (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, >> >>> `reservation_id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, >> >>> `reservation_name` varchar(255) DEFAULT NULL NULL, `created_at` >> >>> datetime DEFAULT NULL NULL, `updated_at` datetime DEFAULT NULL NULL) >> >>> ENGINE=InnoDB >> >> >>> Apparently it tries to create two primary keys and fails. >> >> >>> Kostas >> >> >>> On Aug 30, 9:31 pm, "Craig Demyanovich" <cdemyanov...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> >>> wrote: >> >>>> You could do this: >> >> >>>> script/generate scaffold player player_id:primary_key name:string >> >> >>>> which generates a migration like this >> >> >>>> class CreatePlayers < ActiveRecord::Migration >> >>>> def self.up >> >>>> create_table :players do |t| >> >>>> t.primary_key :player_id >> >>>> t.string :name >> >> >>>> t.timestamps >> >>>> end >> >>>> end >> >> >>>> def self.down >> >>>> drop_table :players >> >>>> end >> >>>> end >> >> >>>> Regards, >> >>>> Craig > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Well, you see this problem remains even when I use generate model and then manually fill the migration with t.primary_key:tablename_id It tries to create a separate id. And if I use :id =>false, so it creates only the tablename_id, I have the same problems as I mentioned above. Kostas On Aug 31, 12:31 am, "Russell Norris" <r...-ftMzyaTR+bHNyFkoKTPOtdi2O/JbrIOy@public.gmane.org> wrote:> Out of sheer curiosity, what''s the compelling reason to ditch Rails'' > convention and change the primary key if you''re still using > scaffolding? > > RSL > > On Sat, Aug 30, 2008 at 6:54 PM, samson78 <ne...-ee4meeAH724@public.gmane.org> wrote: > > > Yes, the primary key is set when I use reservation_id:primary key when > > calling the generate script > > After db:migrate it shows as primary key on the database. > > > Kostas > > > On Aug 30, 11:38 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> On 30 Aug 2008, at 23:15, samson78 wrote: > > >> > The whole thing seems that has a problem with: > > >> > 1)The params:id in the controller > >> > do I leave it as :id or do I write the new primary key, > >> > e.g. :reseravations_id > > >> should be able to leave it as :id - the primary key is always > >> available as id (ie the id method always exists and will return the > >> correct value) > > >> Fred > > >> > 2)in the routes.rb > > >> > map.connect '':controller/:action/:id'' > >> > map.connect '':controller/:action/:id.:format'' > > >> > It cannot get route as it searches for :id > > >> > Kostas > > >> > On Aug 30, 10:33 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >> > wrote: > >> >> On 30 Aug 2008, at 22:23, samson78 wrote: > > >> >>> Thanks for the answer. I run: > >> >>> script/generate scaffold reservation reservation_id:primary_key > >> >>> name:string > > >> >> you need create_table :players, :id => false do |t| ... > > >> >> so that rails doesn''t try to create its primary key as well as your > >> >> own. > > >> >> Fred > > >> >>> followed by > > >> >>> rake db:migrate > > >> >>> and I get the following error: > > >> >>> == 20080830212120 CreateReservations: migrating > >> >>> ==============================> >> >>> -- create_table(:reservations) > >> >>> rake aborted! > >> >>> Mysql::Error: Incorrect table definition; there can be only one auto > >> >>> column and it must be defined as a key: CREATE TABLE `reservations` > >> >>> (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, > >> >>> `reservation_id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, > >> >>> `reservation_name` varchar(255) DEFAULT NULL NULL, `created_at` > >> >>> datetime DEFAULT NULL NULL, `updated_at` datetime DEFAULT NULL NULL) > >> >>> ENGINE=InnoDB > > >> >>> Apparently it tries to create two primary keys and fails. > > >> >>> Kostas > > >> >>> On Aug 30, 9:31 pm, "Craig Demyanovich" <cdemyanov...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >> >>> wrote: > >> >>>> You could do this: > > >> >>>> script/generate scaffold player player_id:primary_key name:string > > >> >>>> which generates a migration like this > > >> >>>> class CreatePlayers < ActiveRecord::Migration > >> >>>> def self.up > >> >>>> create_table :players do |t| > >> >>>> t.primary_key :player_id > >> >>>> t.string :name > > >> >>>> t.timestamps > >> >>>> end > >> >>>> end > > >> >>>> def self.down > >> >>>> drop_table :players > >> >>>> end > >> >>>> end > > >> >>>> Regards, > >> >>>> Craig--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I meant, what''s the compelling reason to not go with Rails'' defaults and use the :id field? If you''re not using a legacy database and all. Most people who need/want to change the primary key are doing so because they are having to support a legacy db with columns already created. You seem to be creating this database for the first time and it''s usually a good idea to go with Rails'' defaults then, unless there''s a compelling reason not to. Which is what I was asking. :) RSL On Sat, Aug 30, 2008 at 7:56 PM, samson78 <nemea-ee4meeAH724@public.gmane.org> wrote:> > Well, you see this problem remains even when I use generate model and > then manually fill the migration with > t.primary_key:tablename_id > It tries to create a separate id. > And if I use :id =>false, so it creates only the tablename_id, I have > the same problems as I mentioned above. > > Kostas > > On Aug 31, 12:31 am, "Russell Norris" <r...-ftMzyaTR+bHNyFkoKTPOtdi2O/JbrIOy@public.gmane.org> wrote: >> Out of sheer curiosity, what''s the compelling reason to ditch Rails'' >> convention and change the primary key if you''re still using >> scaffolding? >> >> RSL >> >> On Sat, Aug 30, 2008 at 6:54 PM, samson78 <ne...-ee4meeAH724@public.gmane.org> wrote: >> >> > Yes, the primary key is set when I use reservation_id:primary key when >> > calling the generate script >> > After db:migrate it shows as primary key on the database. >> >> > Kostas >> >> > On Aug 30, 11:38 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> > wrote: >> >> On 30 Aug 2008, at 23:15, samson78 wrote: >> >> >> > The whole thing seems that has a problem with: >> >> >> > 1)The params:id in the controller >> >> > do I leave it as :id or do I write the new primary key, >> >> > e.g. :reseravations_id >> >> >> should be able to leave it as :id - the primary key is always >> >> available as id (ie the id method always exists and will return the >> >> correct value) >> >> >> Fred >> >> >> > 2)in the routes.rb >> >> >> > map.connect '':controller/:action/:id'' >> >> > map.connect '':controller/:action/:id.:format'' >> >> >> > It cannot get route as it searches for :id >> >> >> > Kostas >> >> >> > On Aug 30, 10:33 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> >> > wrote: >> >> >> On 30 Aug 2008, at 22:23, samson78 wrote: >> >> >> >>> Thanks for the answer. I run: >> >> >>> script/generate scaffold reservation reservation_id:primary_key >> >> >>> name:string >> >> >> >> you need create_table :players, :id => false do |t| ... >> >> >> >> so that rails doesn''t try to create its primary key as well as your >> >> >> own. >> >> >> >> Fred >> >> >> >>> followed by >> >> >> >>> rake db:migrate >> >> >> >>> and I get the following error: >> >> >> >>> == 20080830212120 CreateReservations: migrating >> >> >>> ==============================>> >> >>> -- create_table(:reservations) >> >> >>> rake aborted! >> >> >>> Mysql::Error: Incorrect table definition; there can be only one auto >> >> >>> column and it must be defined as a key: CREATE TABLE `reservations` >> >> >>> (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, >> >> >>> `reservation_id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, >> >> >>> `reservation_name` varchar(255) DEFAULT NULL NULL, `created_at` >> >> >>> datetime DEFAULT NULL NULL, `updated_at` datetime DEFAULT NULL NULL) >> >> >>> ENGINE=InnoDB >> >> >> >>> Apparently it tries to create two primary keys and fails. >> >> >> >>> Kostas >> >> >> >>> On Aug 30, 9:31 pm, "Craig Demyanovich" <cdemyanov...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> >> >>> wrote: >> >> >>>> You could do this: >> >> >> >>>> script/generate scaffold player player_id:primary_key name:string >> >> >> >>>> which generates a migration like this >> >> >> >>>> class CreatePlayers < ActiveRecord::Migration >> >> >>>> def self.up >> >> >>>> create_table :players do |t| >> >> >>>> t.primary_key :player_id >> >> >>>> t.string :name >> >> >> >>>> t.timestamps >> >> >>>> end >> >> >>>> end >> >> >> >>>> def self.down >> >> >>>> drop_table :players >> >> >>>> end >> >> >>>> end >> >> >> >>>> Regards, >> >> >>>> Craig > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Oh right, I am cerating the database for the first time, but I am trying to imitate an existing database (for testing purposes). Because the old app works with the existing database and unfortunately parts of the old app will continue to exist for some time alongside the new components that will be done with RoR.Messy, I know, but not my decision!! Thanks, Kostas --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---