2012-03-18 4 views
-3

Как добавить уникальный, автоматически увеличивающий первичный ключ (IdCustomer) в Rails? А что, если у меня есть более одного ключа?Как добавить первичный ключ в миграцию 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

+0

Кто-нибудь знает? hm – byCoder

ответ

0

Вы не можете установить более 1 колонки auto_increment. Удалите auto_increment PRIMARY KEY после IdCard int(11) DEFAULT NULL и положите UNIQUE вместо этого, если вы хотите сделать эту колонку уникальной.

+0

как это сделать в миграции, я спросил! – byCoder

Смежные вопросы