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 数据库表?


- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- SQL 临时表问题 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 更改自动增量起始编号? 2021-01-01