MySQL 创建一个没有 :id 列的 ActiveRecord 数据库表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/874634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Create an ActiveRecord database table with no :id column?
提问by Stefan
Is it possible for me to create and use a database tablethat contains no :idcolumn in ActiveRecord, Ruby on Rails.
我是否可以在 Ruby on Rails 的 ActiveRecord 中创建和使用不包含:id列的数据库表。
I don't merely want to ignore the id column, but I wish it to be absolutely non-existent.
我不只是想忽略id 列,但我希望它绝对不存在。
Table Example
:key_column :value_column
0cc175b9c0f1b6a831c399e269772661 0cc175b9c0f1b6a831c399e269772661
4a8a08f09d37b73795649038408b5f33 0d61f8370cad1d412f80b84d143e1257
92eb5ffee6ae2fec3ad71c777531578f 9d5ed678fe57bcca610140957afab571
Any more info ( like an :id_column ) would break the whole feature.
任何更多信息(如 :id_column )都会破坏整个功能。
How would I implement something like this in rails?
我将如何在 rails 中实现这样的东西?
回答by matt
yup, looks like this:
是的,看起来像这样:
create_table :my_table, id: false do |t|
t.string :key_column
t.string :value_column
end
just make sure to include the
只要确保包括
id: false
part.
部分。