Ruby on rails 为什么ActiveRecord::StatementInvalid:SQLite3::SQLException:near";)&引用;:语法错误:插入到";用户“友谊”;()值()
为什么ActiveRecord::StatementInvalid:SQLite3::SQLException:near“)”:语法错误:插入到“用户\u友谊”()值中 尝试测试时: $ruby-I test/unit/user\u friendships\u test.rbRuby on rails 为什么ActiveRecord::StatementInvalid:SQLite3::SQLException:near";)&引用;:语法错误:插入到";用户“友谊”;()值(),ruby-on-rails,ruby,activerecord,sqlite,Ruby On Rails,Ruby,Activerecord,Sqlite,为什么ActiveRecord::StatementInvalid:SQLite3::SQLException:near“)”:语法错误:插入到“用户\u友谊”()值中 尝试测试时: $ruby-I test/unit/user\u friendships\u test.rb require 'test_helper' class UserFriendshipsTest < ActiveSupport::TestCase should belong_to (:user) should b
require 'test_helper'
class UserFriendshipsTest < ActiveSupport::TestCase
should belong_to (:user)
should belong_to (:friend)
test "that creating a frinedship works without raising an exception" do
assert_nothing_raised do
UserFriendship.create user: users(:a), friend: friends(:b)
end
end
end
我也遇到了这个。这似乎与破坏rails命名惯例有关。在我的例子中,用“rails g model activity_item”代替“rails g model activity_items”解决了这个问题。该表中是否有列?能否发布UserFriendly的代码以及数据库模式?是的,该表中有列。我刚刚用部分模式更新了帖子
create_table "user_friendships", :force => true do |t|
t.integer "user_id"
t.integer "friend_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "user_friendships", ["user_id", "friend_id"], :name => "index_user_friendships_on_user_id_and_friend_id"
create_table "users", :force => true do |t|
t.string "first_name"
t.string "last_name"
t.string "profile_name"
t.string "email", :default => "", :null => false
t.string "encrypted_password", :default => "", :null => false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", :default => 0, :null => false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
end