【问题标题】:Is "MUL" an acceptable "Primary Key"?“MUL”是可接受的“主键”吗?
【发布时间】:2013-02-28 22:17:06
【问题描述】:

我正在尝试使用 ActiveUUID gem 将我的 Survey 表的主键设置为 UUID。 (MySQL)

即使我有:primary_key => true,它仍然出于某种原因将其设置为MUL?这是预期的吗?

迁移:

class CreateSurveys < ActiveRecord::Migration
  def change
    create_table :surveys, :id => false do |t|
      t.references :employee, :null => false

      t.uuid :id, :primary_key => true
      t.datetime :expired_at

      t.timestamps
    end
    add_index :surveys, :id
  end
end

模型:survey.rb

class Survey < ActiveRecord::Base

  include ActiveUUID::UUID

  belongs_to :employee

  validates :employee, :presence => true  

end

【问题讨论】:

    标签: mysql ruby-on-rails ruby database ruby-on-rails-3


    【解决方案1】:

    我找到了答案。我需要删除add_index :surveys, :id。显然主键已经被索引。解决了它

    【讨论】:

      猜你喜欢
      • 2018-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-25
      • 2016-10-01
      相关资源
      最近更新 更多