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'創建一個記錄。 –