2016-01-06 53 views
0

我正在運行到似乎導致問題的SQLiteException。Rails 4 SQLiteException

Schema.rb

create_table "features", force: :cascade do |t| 
t.string "name_key" 
t.datetime "created_at" 
t.datetime "updated_at" 
end 

add_index "features", ["name_key"], name: "index_features_on_name_key" 

create_table "organizations", force: :cascade do |t| 
    t.string "name" 
    t.string "code" 
    t.datetime "created_at", null: false 
    t.datetime "updated_at", null: false 
end 

create_table "organizations_features", id: false, force: :cascade do |t| 
    t.integer "organization_id" 
    t.integer "feature_id" 
end 

這是當前架構和我明確地創建表organizations_features(仍然可以通過遷移,但是單獨的遷移引用連接表),否則create_join_table將創建「features_organizations」。在這個過程中,如果我跑

耙分貝:滴DB:即使沒有任何表加載一個記錄負載

我仍然不斷收到以下錯誤(我從不:創建DB:架構跑分貝:種子)。

ActiveRecord::StatementInvalid: SQLite3::SQLException: near ")": syntax error: INSERT INTO "organizations_features"() VALUES() 

other question似乎表明,使連接表名稱的所有單數在organization_feature,但由於我們與其他服務共享的模式,這是我們必須使用相同的命名約定。

注意:即使我嘗試使用遷移 「create_join_table」 的問題創建表似乎堅持」

更新:seeds.rb

organization = Organization.create!(name: 'XYZ', code: 'xyz') 
feature = Feature.create!(name_key: 'Some Feature') 
user = User.create!(name: "user1", 
        email: "[email protected]", 
        password:    "password123", 
        password_confirmation: "password123", 
        profile_id: profile.id) 
OrganizationsFeature.create!(feature_id: feature.id, organization_id: organization.id) 

其中OrganizationsFeature看起來像這樣

class OrganizationsFeature < ActiveRecord::Base 
    belongs_to :organization 
    belongs_to :feature 
end 
+0

發佈'seed.rb'文件的內容。用種子文件更新了 –

+0

。 – user1489580

+0

因此,如果有人遇到問題,我發現解決方案也是如此。 – user1489580

回答

0

如果其他人遇到相同問題,我找到了問題的答案。test/fixtures/organizations_features.yml文件有空記錄

one :{} 
two: {} 

這導致空記錄被插入表中。每次加載該數據並因此插入錯誤。 正確的數據/刪除文件解決了問題。