如何在Rails中添加一個唯一的自動遞增主鍵(IdCustomer
)?如果我有一個以上的密鑰呢?如何在Rails遷移中添加主鍵?
class CreateCustomers < ActiveRecord::Migration
def change
create_table :customers do |t|
t.integer :IdCustomer
t.string :Login
t.string :Password
t.string :Email
t.string :Skype
t.integer :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
end
end
end
請幫我解決這個問題,請把它寫在我的代碼上。現在我得到
rake aborted! An error has occurred, all later migrations canceled:
Mysql2::Error: Incorrect table definition; there can be only one auto column and it must be defined as a key: CREATE TABLE
credit_cards
(id
int(11) DEFAULT NULL auto_increment PRIMARY KEY,IdCustomer
int(11),IdCard
int(11) DEFAULT NULL auto_increment PRIMARY KEY,Number
varchar(255),NameOfCard
int(11),ExpiryDate
date,created_at
datetime NOT NULL,updated_at
datetime NOT NULL) ENGINE=InnoDB
有人知道嗎? hm – byCoder 2012-03-22 20:45:46