ruby-on-rails - 为什么ActiveRecord::StatementInvalid:SQLite3::SQLException:在“)附近:语法错误:INSERT INTO“user_friendships”()VALUES()

标签 ruby-on-rails ruby activerecord sqlite

为什么为什么ActiveRecord :: StatementInvalid:SQLite3 :: SQLException:在“)”附近:语法错误:INSERT INTO“ user_friendships”()VALUES()

尝试测试时:

$ ruby​​-我测试test / unit / user_friendships_test.rb

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


任何想法?

更新:他是Schema.rb的一部分

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

最佳答案

我也遇到了这个问题。它似乎与搞乱rails命名约定有关。就我而言,执行“ rails g model activity_item”而不是“ rails g model activity_items”解决了该问题。

关于ruby-on-rails - 为什么ActiveRecord::StatementInvalid:SQLite3::SQLException:在“)附近:语法错误:INSERT INTO“user_friendships”()VALUES(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21590720/

相关文章:

ruby-on-rails - ActiveRecord 数据类型的文档页面在哪里?

ruby-on-rails - 未初始化的常量 Active Scaffold Rails 2.3.5

ruby-on-rails - 查询除具有此集合中 ID 的用户之外的所有用户

ruby-on-rails - Redmine:安装时出现 rake 错误

ruby-on-rails - 运行错误 'requirements_debian_libs_install libssl-dev' ,

ruby-on-rails - Phusion Passenger 正在终止我的进程?

ruby-on-rails - 如何让 Rails 中的 named_scope 返回一个值而不是数组?

ruby-on-rails - 我认为这个查询是错误的吗?

ruby-on-rails - rspec should have_select ('cars' , :options => ['volvo' , 'saab' ] 不工作

ruby-on-rails - 如何自动定期运行我的规范并在失败时收到通知?