在我想要创建的迁移中,表的主键是一个名为“id”的字段,但它不是自动递增整数。它的数据类型应该是uniqueidentifier(一个uuid)。这是我曾尝试过的:使用UUID主键的ActiveRecord迁移
create_table :some_things, :id => false do |t|
t.column :id, :uniqueidentifier, :primary => true
t.column :name, :string, :limit => 255
t.column :type, :tinyint
t.column :deleted_flag, :bit
t.column :class_id, :uniqueidentifier
t.timestamps
end
这创建了表,但没有主键(因为我说:id => false)。如果我说“create_table:some_things,:id => true,:primary =>:id”,那么“id”就成为主键,但它是一个自动递增的整数,而不是非自动递增的uuid。
如何使此迁移工作,以便主键是一个称为“id”类型“uniqueidentifier”(非自动递增)的字段?
我使用: SQL Server 2008中, 的Rails/ActiveRecord的3.0.3, ActiveRecord的 - SQLSERVER适配器宝石, 和ODBC连接。
这是http://stackoverflow.com/questions/1200568/using-rails-how-can-i-set-my-primary-key-to-not-be-an-integer-typed-专栏 - 我们应该整理这些问题吗? – 2013-03-05 02:06:07