如何关闭AUTO_INCREMENT Rails中的Active Record [英] How to turn off auto_increment in Rails Active Record

查看:163
本文介绍了如何关闭AUTO_INCREMENT Rails中的Active Record的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能创建没有 AUTO_INCREMENT 标志中的主键的ActiveRecord

Is it possible to create primary key without auto_increment flag in ActiveRecord?

我不能这样做。

create table :blah, :id => false

因为我想对列主键索引。我抬头一看文档但没有发现任何有用的。

because I want to have primary key index on the column. I looked up documentation but didn't find anything useful.

是否有可能建立主键不AUTO_INCREMENT?

推荐答案

试试这个?

create_table(:table_name, :id => false) do |t|
  t.integer :id, :options => 'PRIMARY KEY'
end

这篇关于如何关闭AUTO_INCREMENT Rails中的Active Record的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆