ruby-on-rails - Rails db:当外键很大时,seed 不会创建记录
问题描述
我正在尝试填充 mysql2 数据库,但并非所有记录都添加到数据库中。
这是我的架构
create_table "accounts", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name_es"
t.string "name_en"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "dbid"
create_table "company_account_categories", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.integer "company_type"
t.integer "account_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["account_id"], name: "index_company_account_categories_on_account_id"
add_foreign_key "company_account_categories", "accounts"
在我的种子中,我的 CompanyAccountCategory 记录的 account_id 介于 101 和 177 之间,这些记录都被写入数据库,而 account_id 为 22077 或更大的记录则没有。
例子:
CompanyAccountCategory.find_or_create_by(account_id: 176, company_type: 4)
CompanyAccountCategory.find_or_create_by(account_id: 22133, company_type: 1)
解决方案
推荐阅读
- html - 如何使页脚响应并使其上的文本水平对齐?
- html - 为什么 z-index 不与这两个正方形重叠?
- c++ - Qt 未定义的参考 vtable
- c# - 在 Revit 中过滤元素并设置参数
- javascript - 单击快速查看按钮时,Vue阻止路由器链接提交
- c# - 捕获 forloop 输出的最小和最快的方法
- html - 如何为div设置边距功能
- c++ - 在这种情况下,我的时间复杂性偏执是否合理?
- javascript - 升级到 expo SDK 37.0.0 后,我的 stackNavigator 标头高度增加了一倍
- android - 删除 Firebase AuthStateListener 以在 onPause() 上进行身份验证并将其添加回 onResume() 的目的