我在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中看到数据库和表。
但是当我尝试在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授予权限,但仍然会得到同样的错误。
我一定错过了什么,有什么解决办法吗?
答案 0 :(得分:0)
我已经弄明白为什么我会收到这个错误。这是因为我的ruby类中的“初始化”,我想它会覆盖“正常”的那个。