gpt4 book ai didi

ruby - `clear_transaction_record_state' : undefined method `[]' for nil:NilClass when creating a record Ruby

转载 作者:行者123 更新时间:2023-11-29 13:49:34 27 4
gpt4 key购买 nike

我正在用 ruby​​ 创建一个独立的项目。我想进行与 Rails 相同的迁移,所以我安装了 gem standalone-migrations .我使用这个 config.yml development 创建了我的数据库:
适配器:postgresql
数据库:gametour
编码:utf8
主机:本地主机
用户名:tylo
密码:~

然后是我如何创建我的第一个迁移:

rake db:new_migration name=flower_type_migration

class FlowerTypeMigration < ActiveRecord::Migration
def change
create_table :flowerTypes do |t|
t.string :type
end
end
end

rake db:migrate

看起来 rake db:migrate 工作正常,因为我可以在 psql 中看到数据库和表。

但是当我尝试在 ruby​​ 中创建记录时:

FlowerTypes.create(:type => "test"}

我收到这个错误:

/var/lib/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/transactions.rb:425:in 'clear_transaction_record_state': undefined method '[]' for nil:NilClass (NoMethodError)
from /var/lib/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/transactions.rb:339:in 'ensure in rollback_active_record_state!'
from /var/lib/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/transactions.rb:339:in 'rollback_active_record_state!'
from /var/lib/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/transactions.rb:318:in 'save'
from /var/lib/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/suppressor.rb:41:in 'save'
from /var/lib/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/persistence.rb:34:in 'create'

我已尝试将权限授予自己 (tylo) 和 PUBLIC,但仍然出现相同的错误。

我一定是遗漏了什么,有什么解决办法吗?

最佳答案

我已经弄清楚为什么会出现此错误。这是因为我的 ruby​​ 类中的“初始化”,我想它会覆盖“正常”类。

关于ruby - `clear_transaction_record_state' : undefined method `[]' for nil:NilClass when creating a record Ruby,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43310133/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com