Mysql 迁移-如何向已填充的表添加唯一约束?
我有一个技师表,它在生产中只包含name和timestamp列,但现在我需要将其用作designe模型Mysql 迁移-如何向已填充的表添加唯一约束?,mysql,ruby-on-rails,ruby,migration,Mysql,Ruby On Rails,Ruby,Migration,我有一个技师表,它在生产中只包含name和timestamp列,但现在我需要将其用作designe模型 class Technician < ActiveRecord::Base validates_presence_of :name validates_uniqueness_of :name end class AddDeviseToTechnicians < ActiveRecord::Migration def change change_
class Technician < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :name
end
class AddDeviseToTechnicians < ActiveRecord::Migration
def change
change_table(:technicians) do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
end
end
end
但我无法迁移,因为电子邮件是一个“唯一:true
”列,也不能删除我的技术人员表。我该怎么办
我正在考虑将每个技术人员的电子邮件字段设置为:name\u attribute+“@email.com”
,但最好的方法是什么?
我使用的是MYSQL数据库。请检查此数据库,您只能使用名称,而不能使用链接中描述的电子邮件和用户名。虽然我怀疑您不需要“名称或电子邮件”,而只需要“名称”,但该情况在不同的指南中介绍: