1
我想创建生成模型,看起来像这样一个迁移:创建独特的范围迁移
# Table name: cities
#
# country_code :text
# created_at :datetime not null
# id :integer not null, primary key
# name :string
# updated_at :datetime not null
#
class City < ActiveRecord::Base
validates :name, presence: true, uniqueness: {:scope => :country_code,
message: "A name and country already exists for this entry" }
end
如何创建一个standalone migration创建这个模式?
我能够使在整个表的:name
独特:
rails g migration CreateCitites name:string:uniq country_code:text timezone:text
我在与创建:name
独特相对于:country_code
问题。
例子:
名称:悉尼,COUNTRY_CODE:澳大利亚
名称:悉尼,COUNTRY_CODE:德国
应该让
名称:悉尼,country_c颂:澳大利亚
名称:悉尼,COUNTRY_CODE:澳大利亚
不应该被允许
**您无法从命令行创建此类型的迁移** –