How can I add a unique, auto-incrementing primary key (IdCustomer) in Rails? And what about if I have more than one key?
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
Help me with this, please, get it on my code. Becouse now i get
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 TABLEcredit_cards
(idint(11) DEFAULT NULL auto_increment PRIMARY KEY,IdCustomer
int(11),IdCardint(11) DEFAULT NULL auto_increment PRIMARY KEY,
Numbervarchar(255),NameOfCardint(11),ExpiryDatedate,
created_atdatetime NOT NULL,updated_atdatetime NOT NULL)
ENGINE=InnoDB
You cannot set more than 1 column
auto_increment. Deleteauto_increment PRIMARY KEYafterIdCard int(11) DEFAULT NULLand putUNIQUEinstead if you want to make that column unique