rails-postgresql

Can't find the 'libpq-fe.h header when trying to install pg gem

杀马特。学长 韩版系。学妹 提交于 2019-12-16 19:52:04
问题 I am using the Ruby on Rails 3.1 pre version. I like to use PostgreSQL, but the problem is installing the pg gem. It gives me the following error: $ gem install pg Building native extensions. This could take a while... ERROR: Error installing pg: ERROR: Failed to build gem native extension. /home/u/.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb checking for pg_config... no No pg_config... trying anyway. If building fails, please try again with --with-pg-config=/path/to/pg_config checking for

Postgres operators for JSON data type using Rails 4

妖精的绣舞 提交于 2019-12-13 00:38:54
问题 Got a record: 2.1.1 :202 > r.column_data => {"data1"=>[1, 2, 3], "data2"=>"data2-3", "array"=>[{"hello"=>1}, {"hi"=>2}], "nest"=>{"nest1"=>"yes"}} Trying to query inside the array object within data1 2.1.1 :203 > Record.where("column_data -> 'data1' -> 2 = '3' ") Record Load (0.8ms) SELECT "records".* FROM "records" WHERE (column_data -> 'data1' -> 2 = '3' ) PG::UndefinedFunction: ERROR: operator does not exist: json = unknown LINE 1: ...* FROM "records" WHERE (column_data -> 'data1' -> 2 =

How can I increase a field in a rails gem?

社会主义新天地 提交于 2019-12-12 02:57:59
问题 I'm getting this error: SQL (31.1ms) INSERT INTO "read_marks" ("readable_id", "readable_type", "timestamp", "user_id") VALUES ($1, $2, $3, $4) RETURNING "id" [["readable_id", nil], ["readable_type", "PublicActivity::ORM::ActiveRecord::Activity"], ["timestamp", Mon, 04 Mar 2013 03:29:52 UTC +00:00], ["user_id", 2]] PG::Error: ERROR: value too long for type character varying(20) Because "readable_type" only holds 20 characters, and I'm passing in "PublicActivity::ORM::ActiveRecord::Activity".

Postgres rails doesn't recognize user

China☆狼群 提交于 2019-12-11 12:57:59
问题 So my rails app gives me the "We're sorry, but something went wrong." When I check the logs, I see PG::Error (FATAL: role "ubuntu" does not exist ): However, when I then do this (note I believe that I never added a password to role ubuntu): sudo -u postgres createuser ubuntu Shall the new role be a superuser? (y/n) y createuser: creation of new role failed: ERROR: role "ubuntu" already exists I'm running this on an ubuntu ec2 instance with nginx server. EDIT: I just tried uninstalling and

Why are all of my tables in Rails 4/Postgres being created with “dimension” of 1?

耗尽温柔 提交于 2019-12-11 06:14:48
问题 I'm running into a LOT of problems just trying to do basic model generations and migrations in Rails 4 with Postgres. I have the pg gem installed, version 0.17.1 . In the beginning, I couldn't even run migrations without errors, because the schema_migrations table was created with the version column having a dimension of 1 . Once I manually changed it to zero, it worked fine. Now, if I look at all of the migrations that resulted from me using the Rails model generator, I see that every single

pg gem install on Mac OS Lion with rvm

跟風遠走 提交于 2019-12-10 22:43:09
问题 212-178-13-214:~ igorfedoronchuk$ gem install pg Building native extensions. This could take a while... /Users/igorfedoronchuk/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:48: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777 ERROR: Error installing pg: ERROR: Failed to build gem native extension. /Users/igorfedoronchuk/.rvm/rubies/ruby-1.9.2-p180/bin/ruby extconf.rb checking for pg_config... yes Using config values from /usr/bin/pg

Postgres: creating a username

北慕城南 提交于 2019-12-10 21:04:31
问题 I'm trying to get started with Postgres on Rails apps on Mac. I made a new rails app called "shawsome" and in the database.yml file it created this development: adapter: postgresql encoding: unicode database: shawsome_development pool: 5 username: shawsome password: But the server wouldn't run because there's no role for "shawsome." Rails just seemed to have inferred the username from the name of my app. I looked at postgres documentation and it talks about CREATE USER command CREATE USER

How do I migrate an ActiveRecord model attribute from json to jsonb?

↘锁芯ラ 提交于 2019-12-10 17:48:34
问题 What should the migration look like? I would like to take advantage of the jsonb array querying technique. 回答1: I would write the migration this way: def change reversible do |dir| dir.up { change_column :models, :attribute, 'jsonb USING CAST(attribute AS jsonb)' } dir.down { change_column :models, :attribute, 'json USING CAST(attribute AS json)' } end end I don't know how this compares performance-wise to other solutions, but I tested this on a table with 120,000 records, each record having

Can't store array in json field in postgresql (rails) can't cast Array to json

你。 提交于 2019-12-10 15:39:19
问题 This is the error I'm getting when I run db:migrate rake aborted! can't cast Array to json This is my table class CreateTrips < ActiveRecord::Migration def change create_table :trips do |t| t.json :flights t.timestamps end end end This is in my seeds.rb file flights = [{ depart_time_hour: 600, arrive_time_hour: 700, passengers: [ { user_id: 1, request: true } ] }] trip = Trip.create( { name: 'Flight', flights: flights.to_json } ) For some reason I can't do this. If I do this. trip = Trip

Rails database-specific data type

时光毁灭记忆、已成空白 提交于 2019-12-10 11:15:17
问题 This is the first time I've tried out Rails with PostgreSQL. I am confused by the lack of timestamp with timezone usage in code I usually see regarding columns storing absolute time. A prime example is devise, it stores columns a datetime column which translates to a timestamp with out timezone in PostgreSQL. I consider it a bad practice because timestamp with out timezone could mean any time zone. If you were accessing the database from another application, you would have no idea which time