Mysql 如何在Rails迁移中添加主键?
如何在Rails中添加唯一的、自动递增的主键(Mysql 如何在Rails迁移中添加主键?,mysql,ruby-on-rails,migration,Mysql,Ruby On Rails,Migration,如何在Rails中添加唯一的、自动递增的主键(IdCustomer)?如果我有多把钥匙呢 class CreateCustomers < ActiveRecord::Migration def change create_table :customers do |t| t.integer :IdCustomer t.string :Login t.string :Password t.string :Email t.s
IdCustomer
)?如果我有多把钥匙呢
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
class-CreateCustomers
请帮我,把它记在我的密码上。因为现在我明白了
雷克流产了!发生错误,所有后续迁移均已取消:
Mysql2::错误:表定义不正确;只能有一辆汽车
列,并且必须将其定义为键:创建表信用卡
(id
int(11)默认空自动增量主键,IdCustomer
int(11),IdCard
int(11)默认空自动增量主键,
Number
varchar(255),NameOfCard
int(11),ExpiryDate
date,
在
日期时间不为空时创建,在
日期时间不为空时更新)
引擎=InnoDB
您不能设置超过1列的
自动增量
。在IdCard int(11)DEFAULT NULL
之后删除auto_increment主键
,如果您想使该列唯一如何在迁移中做到这一点我问过!