`clear_transaction_record_state': 创建记录 Ruby 时 nil:NilClass 的未定义方法 `[]'
`clear_transaction_record_state': undefined method `[]' for nil:NilClass when creating a record Ruby
我正在 ruby 中创建一个独立项目。我想进行与 rails 相同的迁移,所以我安装了 gem standalone-migrations。我使用这个 config.yml development:
adapter: postgresql
database: gametour
encoding: utf8
host: localhost
username: tylo
password: ~
创建了我的数据库
然后我是如何创建我的第一个迁移的:
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 中看到数据库和 table。
但是当我尝试在 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 class 中的 "initialize",我想它会覆盖 "normal" 一个。
我正在 ruby 中创建一个独立项目。我想进行与 rails 相同的迁移,所以我安装了 gem standalone-migrations。我使用这个 config.yml development:
adapter: postgresql
database: gametour
encoding: utf8
host: localhost
username: tylo
password: ~
然后我是如何创建我的第一个迁移的:
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 中看到数据库和 table。
但是当我尝试在 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 class 中的 "initialize",我想它会覆盖 "normal" 一个。