ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin16]
This began to occur after tweaking the settings around --binstubs.
The following are generated files.
bin/brakeman
bin/bundle-audit
bin/bundler-audit
bin/byebug
bin/cap
bin/capify
bin/chromedriver-helper
bin/chromedriver-update
bin/coderay
bin/console
bin/dotenv
bin/fission
bin/fog
bin/foreman
bin/generate-api
bin/haml
bin/htmldiff
bin/httpclient
bin/ldiff
bin/listen
bin/maruku
bin/marutex
bin/nokogiri
bin/pry
bin/rackup
bin/rbvmomish
bin/restclient
bin/rspec
bin/rubocop
bin/ruby-parse
bin/ruby-rewrite
bin/sass
bin/sass-convert
bin/scss
bin/sprockets
bin/thor
bin/tilt
bin/unicorn
bin/unicorn_rails
bin/whenever
bin/wheneverize
The following is the message on the terminal.
20:39:07 web.1 | Beginning in Rails 4, Rails ships with a `rails` binstub at ./bin/rails that
20:39:07 web.1 | should be used instead of the Bundler-generated `rails` binstub.
20:39:07 web.1 |
20:39:07 web.1 | If you are seeing this message, your binstub at ./bin/rails was generated by
20:39:07 web.1 | Bundler instead of Rails.
20:39:07 web.1 |
20:39:07 web.1 | You might need to regenerate your `rails` binstub locally and add it to source
20:39:07 web.1 | control:
20:39:07 web.1 |
20:39:07 web.1 | rails app:update:bin # Bear in mind this generates other binstubs
20:39:07 web.1 | # too that you may or may not want (like yarn)
20:39:07 web.1 |
20:39:07 web.1 | If you already have Rails binstubs in source control, you might be
20:39:07 web.1 | inadverently overwriting them during deployment by using bundle install
20:39:07 web.1 | with the --binstubs option.
20:39:07 web.1 |
20:39:07 web.1 | If your application was created prior to Rails 4, here's how to upgrade:
20:39:07 web.1 |
20:39:07 web.1 | bundle config --delete bin # Turn off Bundler's stub generator
20:39:07 web.1 | rails app:update:bin # Use the new Rails executables
20:39:07 web.1 | git add bin # Add bin/ to source control
20:39:07 web.1 |
20:39:07 web.1 | You may need to remove bin/ from your .gitignore as well.
20:39:07 web.1 |
20:39:07 web.1 | When you install a gem whose executable you want to use in your app,
20:39:07 web.1 | generate it and add it to source control:
20:39:07 web.1 |
20:39:07 web.1 | bundle binstubs some-gem-name
20:39:07 web.1 | git add bin/new-executable
20:39:07 web.1 |
Which setting should I change to fix it?
Related
I have successfully deployed my Rails app with Heroku, heroku run rails db:migrate, although heroku run rails db:seed failed.
Here is the error message
➜ quote-editor git:(master) heroku run rails db:seed
Running rails db:seed on ⬢ awesome-quote-editor... up, run.6832 (Free)
== Seeding the database with fixtures ==
WARNING: Rails was not able to disable referential integrity.
This is most likely caused due to missing permissions.
Rails needs superuser privileges to disable referential integrity.
cause: PG::InsufficientPrivilege: ERROR: permission denied: "RI_ConstraintTrigger_c_783704777" is a system trigger
rails aborted!
ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: insert or update on table "line_item_dates" violates foreign key constraint "fk_rails_048689f618"
DETAIL: Key (quote_id)=(309456473) is not present in table "quotes".
My setup
Ubuntu 20.04.2
Ruby 3.1.2
Rails 7.0.4
pg 1.4.3 with native extensions
I have both tried to give superuser privileges
ALTER USER myuser WITH SUPERUSER;
and
GRANT ALL PRIVILEGES ON DATABASE quote_editor_production TO myuser;
List of databases
Name | Owner | Encoding | Collate | Ctype | Access
----------------------------- | -------- | -------- | ------- | ------- | ------------
quote_editor_development | paulinetw | UTF8 | C.UTF-8 | C.UTF-8 |
----------------------------- | -------- | -------- | ------- | ------- | ------------
quote_editor_production | paulinetw | UTF8 | C.UTF-8 | C.UTF-8 | =Tc/paulinetw
quote_editor_test | paulinetw | UTF8 | C.UTF-8 | C.UTF-8 |
database.yml
default: &default
adapter: postgresql
encoding: unicode
development:
<<: *default
database: quote_editor_development
test:
<<: *default
database: quote_editor_test
production:
<<: *default
database: quote_editor_production
username: quote_editor
password: <%= ENV["QUOTE_EDITOR_DATABASE_PASSWORD"] %>
I have tried a lot of suggestions but still can't find a way out. I will really appreciate if somebody could help.
ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: insert or update on table "line_item_dates" violates foreign key constraint "fk_rails_048689f618" DETAIL: Key (quote_id)=(309456473) is not present in table "quotes".
Your seed file is trying to use a Quote with ID 309456473, but that quote doesn't exist.
UPDATE:
Here are my assumptions:
In producution, you run heroku run rails db:migrate, which works
In production, you run heroku run rails db:seed, which fails.
In your seed file you have some command that relies upon some code similar to Quote.find(309456473) and this fails in production
In your seed file, when you create Quotes, you are manually setting each quote's ID as you create it.
Setting the ID of your records on creation is not a good idea. Let the Db generate keys.
In your seed file, wherever you are looking up records by ID, find a different method to locate the record you want by some other attribute.
Don't assume that Heroku Postgres respects or preserves your record IDs from the seed file.
My Rails app is on Heroku and needs access to S3. As such, I have a .env file at the root of my directory with the AWS authentication bits. Simply running rails s will not use the env file, so I need to test my server with heroku local. However, this will not spit out any of the standard rails output. I did try heroku logs and heroku logs -t.
My procfile:
web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}
My env file:
RACK_ENV=development
PORT=3000
AWS_ACCESS_KEY_ID=MYSECRETACCESSKEYID
AWS_SECRET_ACCESS_KEY=mySECRETaccessKEY
S3_BUCKET=my-bucket
AWS_REGION=us-east-1
After running heroku local:
[OKAY] Loaded ENV .env File as KEY=VALUE Format
1:33:45 PM web.1 | Ignoring http_parser.rb-0.6.0 because its extensions are not built. Try: gem pristine http_parser.rb --version 0.6.0
1:33:46 PM web.1 | Puma starting in single mode...
1:33:46 PM web.1 | * Version 4.3.5 (ruby 2.6.3-p62), codename: Code Name
1:33:46 PM web.1 | * Min threads: 5, max threads: 5
1:33:46 PM web.1 | * Environment: development
1:33:48 PM web.1 | * Listening on tcp://0.0.0.0:3000
1:33:48 PM web.1 | Use Ctrl-C to stop
Expected results: whenever I make a request to the endpoint, I expect it to log the endpoint, the SQL commands, and the errors, like it usually does.
I think I figured it out. Since we are not calling rails s directly, (my procfile is calling bundle exec puma), I looked on StackOverflow for similar questions involving puma and found this.
I needed to open a second terminal and run tail -f logs/development.log.
PG::UndefinedTable: ERROR
I am trying to deploy a Rails 4 app on Heroku with a postgres database. I have precompiled assets, but now when I run:
heroku run rake db:migrate
I get this error:
PG::UndefinedTable: ERROR: relation "users" does not exist
: ALTER TABLE "users" ADD COLUMN "invited_by_user_id" integer
rake aborted!
Commonly suggested solutions on Stack Overflow:
I have tried resetting the database with:
heroku pg:reset
The database resets, but I still can't run db:migrate.
I have also tried:
heroku run db:setup
but I get an error that says:
FATAL: permission denied for database "postgres"
DETAIL: User does not have CONNECT privilege.
I was using Rails 4.1.8, and saw this question which suggested maybe I needed to update to rails 4.1.9 or above, but even now that I'm using Rails 4.2.2, no luck.
Additional possibly relevant info:
Connecting to the postgres database on heroku with
heroku pg:psql
then listing the databases with '\l' gives me a long list of databases with cryptic names:
Name | Owner | Encoding | Collate | Ctype | Access privileges
----------------+----------------+----------+-------------+-------------+-----------------------------------
d100o5a2gii5he | rdxtahlqikernc | UTF8 | en_US.UTF-8 | en_US.UTF-8 | rdxtahlqikernc=CTc/rdxtahlqikernc
d102ehvv3umqam | ibuffadisyolrb | UTF8 | en_US.UTF-8 | en_US.UTF-8 | ibuffadisyolrb=CTc/ibuffadisyolrb
d103n2kea6j5sa | tzzkfcinullytw | UTF8 | en_US.UTF-8 | en_US.UTF-8 | tzzkfcinullytw=CTc/tzzkfcinullytw
d10597iiu347nk | eltovdzaxajtiu | UTF8 | en_US.UTF-8 | en_US.UTF-8 | eltovdzaxajtiu=CTc/eltovdzaxajtiu
d108g0imdgn865 | pvzysfivyhcnaa | UTF8 | en_US.UTF-8 | en_US.UTF-8 | pvzysfivyhcnaa=CTc/pvzysfivyhcnaa
...
dvs2j8tkv153m | zjefhzzizozpwy | UTF8 | en_US.UTF-8 | en_US.UTF-8 | zjefhzzizozpwy=CTc/zjefhzzizozpwy
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | postgres=CTc/postgres
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | postgres=CTc/postgres
(4787 rows)
I'm not sure exactly how to interpret that.
I am relatively new new to Rails, but have successfully setup several databases on Heroku in the past. Following the Heroku documentation hasn't helped, and I'm not sure where to go from here.
How can I get db:migrate to complete without errors?
NOTE: I solved this just after posting. See answer below.
Minutes after posting this question I figured it out, and I'm hoping this might help someone else out.
The solution was to upgrade from Rails 4.1.8 to Rails 4.2.2.
Then run
heroku run rake db:schema:load
before
heroku run rake db:migrate
For some reason that wouldn't run for my project with Rails 4.1.8. So, after upgrading to Rails 4.2.2, I ran the schema load and migrate commands with no errors.
I'm using Thin webserver with RoR on my iMac.
I start it with $ foreman start
It was working fine, but now I'm getting this in the console:
09:27:10 web.1 | => Booting Thin
09:27:10 web.1 | => Rails 3.1.3 application starting in development on http://0.0.0.0:5000
09:27:10 web.1 | => Call with -d to detach
09:27:10 web.1 | => Ctrl-C to shutdown server
09:27:10 web.1 | >> Thin web server (v1.3.1 codename Triple Espresso)
09:27:10 web.1 | >> Maximum connections set to 1024
09:27:10 web.1 | >> Listening on 0.0.0.0:5000, CTRL+C to stop
09:27:10 web.1 | Exiting
09:27:11 web.1 | process terminated
09:27:11 system | sending SIGTERM to all processes
And the $ prompt shows up - so the webserver isn't running.
Any ideas?
I just ran $ thin start
and got:
Using rack adapter
/Users/burtondav/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.22/lib/bundler/runtime.rb:31:in `block in setup': You have already activated rack 1.4.1, but your Gemfile requires rack 1.3.6. Using bundle exec may solve this. (Gem::LoadError)
What bundle exec command should I try?
Add the gem 'thin' in your application Gemfile and execute the bundle exec thin start to resolve the version conflict problem.
When I run foreman I get the following:
> foreman start
16:47:56 web.1 | started with pid 27122
Only if I stop it (via ctrl-c) it shows me what is missing:
^CSIGINT received
16:49:26 system | sending SIGTERM to all processes
16:49:26 web.1 | => Booting Thin
16:49:26 web.1 | => Rails 3.0.0 application starting in development on http://0.0.0.0:5000
16:49:26 web.1 | => Call with -d to detach
16:49:26 web.1 | => Ctrl-C to shutdown server
16:49:26 web.1 | >> Thin web server (v1.3.1 codename Triple Espresso)
16:49:26 web.1 | >> Maximum connections set to 1024
16:49:26 web.1 | >> Listening on 0.0.0.0:5000, CTRL+C to stop
16:49:26 web.1 | >> Stopping ...
16:49:26 web.1 | Exiting
16:49:26 web.1 | >> Stopping ...
How do I fix it?
I’ve been able to resolve this issue by 2 different ways:
From https://github.com/ddollar/foreman/wiki/Missing-Output:
If you are not seeing any output from your program, there is a likely
chance that it is buffering stdout. Ruby buffers stdout by default. To
disable this behavior, add this code as early as possible in your
program:
# ruby
$stdout.sync = true
By installing foreman via the heroku toolbelt package
But I still don’t know what’s happening nor why this 2 ways above resolved the issue…
My solution was to put $stdout.sync = true at the top of config/environments/development.rb.
Then everything that loads the development environment (incluing thin) will not buffer stdout.
"Foreman will display to the terminal output anything written to stdout by the processes it launches." - ddollar See foreman-issues#57
BTW, you can use tailf into Procfile to see logs
web: bundle exec rails server thin -p $PORT
log: tail -f log/development.log
Tip: tailf doesn't exist in OSX, using tail -f -n 40 log/development.log works.
I also had the same problem but with a different solution. (ruby 1.9.2p290, rails 3.1.0, ubuntu 10.04.3)
I changed the line in my Procfile from:
web: bundle exec thin start -p $PORT
to:
web: bundle exec rails server thin -p $PORT
and it no longer gave me an issue.
I have the same problem (ruby 1.9.3-p0, rails 3.2rc2, OSX 10.7).
Resolved the issue by using foreman-0.27.0 by adding this line into my Gemfile.
gem 'foreman', '0.27.0'
If you are using Foreman to run a Python project, rather than a Ryby project, and you're having the same issue, here are some solutions for you. If you are using a Procfile to invoke the python CLI directly, then you can use the '-u' option to avoid stdout buffering:
python -u script.py
If you are using a Procfile to manage a WSGI server, such as invoking gunicorn, flask, bottle, eve, etc., then you can add a ".env" file to the root of your python project, containing the following:
PYTHONUNBUFFERED=True