0
我在ruby中创建了一个独立的项目。我希望与rails具有相同的迁移,因此我已安装gem standalone-migrations。`clear_transaction_record_state':未定义的方法`[]'为nil:NilClass创建记录时Ruby
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
好像耙分贝:迁移工作正常,因为我可以看到在PSQL数据库和表我使用这个config.yml development: adapter: postgresql database: gametour encoding: utf8 host: localhost username: tylo password: ~
那么我如何创建我的第一个迁移创建我的数据库。
但是当我尝试在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)和公开,但仍得到相同的错误。
我必须错过一些东西,有没有解决这个问题的方法?
如果你选择* FROM“flowerTypes”;'?未加引号的标识符在PostgreSQL中折叠为小写,所以如果创建混合大小写表名,则必须在任何地方引用它。 –
它与报价是合作哈哈。我认为这个问题与ruby有关,但它似乎不是这种情况,你有没有关于创建不工作的想法?谢谢btw我不知道。 – TyLO
(1)PostgreSQL的最佳做法是用小写字母来创建表名(和其他标识符),用下划线分隔单词,这样您就不用担心引用了。 (2)我没有在该表中看到一个'name'列,但是你想用'name'创建一个记录。 –