I need to create a table replacing default integer id with a string id and making a combo of (id and version) unique primary key. Here is what I''ve got so far. class CreateCatalogs < ActiveRecord::Migration def self.up create_table :catalogs, :id => false do |t| t.string :id, :limit => 20, :null => false t.string :version, :default => ''01'' t.timestamps end end def self.down drop_table :catalogs end end --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
hi slave,you can do it use the connection method of migration use it like ActiveRecord::Base.connection_pool.checkout 2009/4/9 slava <slava_mikerin-/E1597aS9LQAvxtiuMwx3w@public.gmane.org>> > I need to create a table replacing default integer id with a string id > and making a combo of (id and version) unique primary key. Here is > what I''ve got so far. > > class CreateCatalogs < ActiveRecord::Migration > def self.up > create_table :catalogs, :id => false do |t| > t.string :id, :limit => 20, :null => false > t.string :version, :default => ''01'' > > t.timestamps > end > end > > def self.down > drop_table :catalogs > end > end > > > >-- 明天会更好 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
alternatively if i leave default integer id as primary key I need to make sure combo of name and version are unique. create_table :catalogs do |t| t.string :name t.string :version, :default => ''01'' t.timestamps end --~--~---------~--~----~------------~-------~--~----~ 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 Thu, Apr 9, 2009 at 6:56 AM, slava <slava_mikerin-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> > > alternatively if i leave default integer id as primary key I need to > make sure combo of name and version are unique. > > create_table :catalogs do |t| > t.string :name > t.string :version, :default => ''01'' > t.timestamps > end > > >To ensure uniqueness, you can add an index add_index :catalogs, [:name, :version], :unique => true Andrew Timberlake http://ramblingsonrails.com http://www.linkedin.com/in/andrewtimberlake "I have never let my schooling interfere with my education" - Mark Twain --~--~---------~--~----~------------~-------~--~----~ 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 the same subject.. I need to ensure uniqness of name in a table. I tried setting collumn to unique (see below) but that did not work. I still can create records with same name field. create_table :properties do |t| t.string :name, :unique => true t.string :description t.timestamps end --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Reasonably Related Threads
- Application error Rails application failed to start properly"
- undefined method `create_table'' for #<LoginController:0x5e60
- Best Forum? Was: Migration doesn''t seem to preserve create_table options in schema
- cant get X on domainU
- `require': no such file to load -- rspec/rails (LoadError)