How can I set primary key for my IdClient field? I have tried all methods, but I’ll get errors (rails 3.0.9)… Could you help me?
class CreateCustomers < ActiveRecord::Migration
def self.up
create_table :customers do |t|
t.integer :IdCustomer
t.string :username
t.string :crypted_password
t.string :password_salt
t.string :persistence_token
t.string :email
t.string :Skype
t.string :ICQ
t.string :Firstname
t.string :Lastname
t.string :Country
t.string :State
t.string :City
t.string :Street
t.string :Building
t.integer :Room
t.string :AddressNote
t.date :DateOfReg
t.integer :CustGroup
t.float :TotalBuy
t.timestamps
add_index(:customers, :IdCustomer, :unique => true)
end
end
def self.down
drop_table :customers
end
end
Also how to set relations in model?
Don’t do this. Use the built-in
idfield as the primary key. If you’re going to use Rails, you should build your app the “Rails way” unless you have very good reason not to.If you really want to do this, you can pass a
:primary_keyoption tocreate_table:You’ll also need to tell your model the name of its primary key via
self.primary_key = "idClient"