Tag: psql

ActiveRecord :: StatementInvalid:PG ::错误:错误:必须是数据库的所有者

我是rails的新手,当我尝试运行bundle exec rake test:prepare时发生了一些错误bundle exec rake test:prepare ,问了同样的问题点击这里 ,我已经包含了psql输出。 有人可以帮忙吗? 谢谢。 我得到了流动的错误: rake aborted! ActiveRecord::StatementInvalid: PG::Error: ERROR: must be owner of database testp00 : DROP DATABASE IF EXISTS “testp00” /Users/snailwalker/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.0.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `exec’ /Users/snailwalker/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.0.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `block in execute’ /Users/snailwalker/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:435:in `block in log’ /Users/snailwalker/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-(required)>’ /Users/snailwalker/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.0.2/lib/active_record/railties/databases.rake:370:in `block (3 levels) in ‘ Tasks: TOP => db:test:load => db:test:purge (See full trace […]

按上下文获取所有标记,用于act-as-taggable-on

我们使用https://github.com/mbleigh/acts-as-taggable-on为我们的Rails应用程序,我们遇到了一个问题。 我们根据推荐的( Acts-as-taggable-on按上下文查找所有标签 ) Model.tag_context_counts告诉用户给定模型和上下文的可能标签,但这会产生非常低效的查询。 随着我们网站的不断发展,这已成为一个问题。 由于某种原因,它产生了这样的事情: SELECT recipes.id FROM “recipes” ORDER BY sort_order SELECT tags.*, taggings.tags_count AS count FROM “tags” JOIN (SELECT taggings.tag_id, COUNT(taggings.tag_id) AS tags_count FROM “taggings” INNER JOIN example ON example.id = taggings.taggable_id WHERE (taggings.taggable_type = ‘Example’ AND taggings.context = ‘example_context’) AND (taggings.taggable_id IN(41,98,92,57,100,93,60,101,59,134,139,224,204,21,158,238,228,251,82,160,146,80,136,182,221,66,171,62,216,76,159,86,87,126,153,218,227,189,242,142,112,3,14,61,156,131,52,13,46,135,44,174,138,81,68,33,120,114,125,94,104,50,252,130,106,40,151,212,16,229,38,192,233,65,183,37,129,214,202,193,200,47,245,165,132,63,25,75,35,198,217,111,56,23,117,78,58,127,90,39,190,211,210,145,173,180,167,48,157,222,140,215,74,150,103,83,53,199,88,176,209,161,17,170,128,144,257,99,191,234,8,15,223,177,91,179,19,232,187,69,163,107,184,237,89,195,235,241,26,246,231,175,225,250,95,70,172,168,206,154,77,9,208,2,240,73,36,84,118,201,249,4,239,236,119,185,124,254,253,27,85,162,123,148,121,244,181,32,220,141,186,116,149,248,230,20,11,110,67,22,28,122,203,113,178,31,152,18,42,115,143,205,72,10,49,108,137,166,55,188,196,147,7,243,97,155,194,1,207,6,51,12,102,219,64,5,197,105,54,96,29,109,30,164,226,71,24,133,213,247,79,255,258,256,169)) GROUP BY taggings.tag_id HAVING COUNT(taggings.tag_id) > 0) AS […]

外国人 – 删除外键

我想在我的rails 4 app中使用mailboxer。 当我尝试部署数据库时出现问题。 创建邮箱会话表时出错,该表在通知表中具有依赖关系。 我正在尝试删除通知对话的外键。 我创建了一个迁移说: change_table :notifications do |t| t.remove_foreign_key :conversations 然而,rake中止并说外键不存在。 rake aborted! An error has occurred, this and all later migrations canceled: PG::UndefinedObject: ERROR: constraint “notifications_conversation_id_fk” of relation “notifications” does not exist 我的架构包括:add_foreign_key“notifications”,“conversation”,name:“notifications_on_conversation_id” 我试图挖掘db:migrate:down创建邮箱的原始迁移,但也收到错误,说’找不到命令’。 有人可以帮忙吗? 谢谢。

PG :: InvalidTextRepresentation:ERROR:整数的输入语法无效:“M”

所以我的用户模型上有一个性别列,它当前是一个字符串,我想把它改成一个整数,然后将男性’1’和女性’0’,因为它现在是男性“M”女性“F”。 运行此迁移时: class ChangeGenderToIntegerOnUser < ActiveRecord::Migration def change change_column :users, :gender, 'integer USING CAST(gender AS integer)' end end 我收到以下错误: 错误信息: PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: “M” : ALTER TABLE “users” ALTER COLUMN “gender” TYPE integer USING CAST(gender AS integer)/usr/local/rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `exec’ 我该怎么做才能将性别正确地改为整数? 提前致谢!