Create an ActiveRecord database table with no :id column?(创建一个没有 :id 列的 ActiveRecord 数据库表?)
问题描述
我是否可以在 Ruby on Rails 的 ActiveRecord 中创建和使用不包含 :id 列的数据库表.
Is it possible for me to create and use a database table that contains no :id column in ActiveRecord, Ruby on Rails.
我不只是想忽略 id 列,但我希望它绝对不存在.
I don't merely want to ignore the id column, but I wish it to be absolutely non-existent.
Table Example
:key_column :value_column
0cc175b9c0f1b6a831c399e269772661 0cc175b9c0f1b6a831c399e269772661
4a8a08f09d37b73795649038408b5f33 0d61f8370cad1d412f80b84d143e1257
92eb5ffee6ae2fec3ad71c777531578f 9d5ed678fe57bcca610140957afab571
任何更多信息(如 :id_column )都会破坏整个功能.
Any more info ( like an :id_column ) would break the whole feature.
我将如何在 Rails 中实现这样的功能?
How would I implement something like this in rails?
推荐答案
是的,看起来像这样:
create_table :my_table, id: false do |t|
t.string :key_column
t.string :value_column
end
只要确保包含
id: false
部分.
这篇关于创建一个没有 :id 列的 ActiveRecord 数据库表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:创建一个没有 :id 列的 ActiveRecord 数据库表?


基础教程推荐
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01