I am trying to delete an instance from a Post model on a Heroku database. From the command line, should 'heroku run Post.first.delete' work? I've been trying this and it doesn't seem to work and I can't find how to do this. All help is appreciated.
heroku run X won't directly put you into a Rails console.
As per this article you'll want:
heroku run rails console
From there you can delete records.
Related
So I know I can do things like run rails console and change user values in my local environment. How does this apply to something like my rails app when deployed to heroku? Can I use the rails console there?
Of course you can, with Heroku Toobelt you can run heroku run rails console, more here: https://devcenter.heroku.com/articles/getting-started-with-rails4#console
I'm cloning a RoR app from Github. After the clone I install my gems. Now at this point my question/problem arises. Some research I've done suggests I do a
rake db:create
followed by a
rake db:migrate
I've tried both of those steps but am still having trouble.
When I run
rails console
and do something like Plan.first it returns nil. And when I try to visit my application I get an ActiveRecord::RecordNotFound in PagesController#home error alluding to the fact that it can't find the plan id of 1.
Any help is much appreciated.
Thanks in advance!
You have an empty database with no data in it, if seeds are provided - rake db:seed will help, otherwise you'll have to create initial data youself (in rails console, or may be directly in db)
I am trying to view my Heroku app's schema in Terminal (Mac OS X Lion) and stumbled upon a command that does just that. In Terminal, I run heroku run more db/schema.rb but it seems to display an older schema version. I just migrated the Heroku db and I noticed that none of the new columns are listed.
I can't seem to find anything helpful in Heroku's documentation. Does anyone know a command to view the current database schema for a Heroku app?
By the way, I inherited the code for the app and for some reason all of the migration files are commented out (there are probably 40+ files) so I can't just run rake db:migrate locally to update the schema; hence, I'd like to see the Heroku app's schema directly.
Any suggestions?
You could run heroku pg:psql to fire up a Postgres console, then issue \d to see all tables, and \d tablename to see details for a particular table.
For a rails schema, try:
$ heroku run "bundle exec rake db:schema:dump && cat db/schema.rb"
You can use rateaux:
rake db:view:schema
I'm using Ubuntu, with Rails 3.0.1 with mysql2 socket.
When i do runing install, rake db:create and after rails server, my Welcome aboard, shows ActiveRecord::ConnectionNotEstablished in About your application’s environment
What i do?
Had the same problem on rails 3.1.1:
rake db:create - ok
rails console and some DMLs - ok
but accessing info from the web-page resulted in ActiveRecord::ConnectionNotEstablished.
A rails server restart helped.
It sounds like your MySQL server isn't running. You'll need to install MySQL if you haven't already (apt-get install mysql-server should do it). Once it's running, you'll need to set up a user and database for your app, and note the username and password so that you can put that information in config/database.yml within your app.
This link will be useful if you need any help with those steps.
You'll need to do some more debugging to work it out.
How are you running your server?
Make yourself a model.
rails generate model Something name:string
Then try running rake db:migrate
Does this work?
If it does, then you must be running your server in a different way (maybe you're running it in production mode?)
Try rails console and try to do Something.count
If all of those work
then I'd suggest you try restarting your server.
rails server
I've run a migration adding active column to users using heroku rake db:migrate.
and succesfully. but when I run the application the "active" column/attributes is not defined.
I already try to migrate:down and run migrate again for that version.. but it's still not worked.
did you add :active to the list of accessible attributes?
attr_accessible :active
failing that, sometimes you need to run heroku rake db:restart
and just finally, if it's still not working, run heroku logs and you will probably find something
Try this, it will run both the up and the down which will help you better analyze the situation. Also, there may be a problem in your migrations, if you post the code I should be able to asset further.
rake db:migrate:redo
Try to restart you application or drop database, if it doesnt contain valuable information.