无法将UUID设置为MySQL中Rails 4模型的主键

无法将UUID设置为MySQL中Rails 4模型的主键,mysql,ruby-on-rails-4,web-applications,model,migration,Mysql,Ruby On Rails 4,Web Applications,Model,Migration,正在尝试将UUID作为ID主键。MySQL不识别任何东西。除非我对迁移发出“execute”命令;但我不想在每张桌子上重复这一点 (尝试在此设置主键) actor.rb class Actor < ActiveRecord::Base include UUIDHelper self.primary_key = 'id' end module UUIDHelper def self.included(base) base.before_create :assign

正在尝试将UUID作为ID主键。MySQL不识别任何东西。除非我对迁移发出“execute”命令;但我不想在每张桌子上重复这一点

(尝试在此设置主键)

actor.rb

class Actor < ActiveRecord::Base

  include UUIDHelper
  self.primary_key = 'id'

end
module UUIDHelper

  def self.included(base)
    base.before_create :assign_uuid
    base.primary_key = 'id'
  end

  private
  def assign_uuid
    self.id = UUIDTools::UUID.timestamp_create().to_s.downcase if id.blank?
  end

end
class CreateActors < MainMigration
  def change
    create_table :actors, :id => false do |t|
      t.string :id, :limit => 36, primary_key: true, null: false
      t.string :name, :limit => 64, :required => true
      t.string :logo, :limit => 512
    end
  end
end
(如果我确实喜欢“执行alter table…”就可以工作,但我希望保持干燥)

20151028065430_create_actors.rb

class Actor < ActiveRecord::Base

  include UUIDHelper
  self.primary_key = 'id'

end
module UUIDHelper

  def self.included(base)
    base.before_create :assign_uuid
    base.primary_key = 'id'
  end

  private
  def assign_uuid
    self.id = UUIDTools::UUID.timestamp_create().to_s.downcase if id.blank?
  end

end
class CreateActors < MainMigration
  def change
    create_table :actors, :id => false do |t|
      t.string :id, :limit => 36, primary_key: true, null: false
      t.string :name, :limit => 64, :required => true
      t.string :logo, :limit => 512
    end
  end
end
class-CreateActorsfalse do | t|
t、 字符串:id,:limit=>36,主键:true,null:false
t、 字符串:name,:limit=>64,:required=>true
t、 字符串:logo,:limit=>512
结束
结束
结束
如何使“id”成为主键