I am using instant rails which makes use of SQLite and I am unable to connect to the database. I have been using a tutorial that uses MySQL and I have been unable to find instructions for SQLite. Any suggestions?
You could install sqlite.
Or, assuming you have mysql installed, you could change your config/database.yml file to use mysql instead of sqlite.
(From using rails -d mysql testapp)
development:
adapter: mysql
encoding: utf8
reconnect: false
database: awesome_development
pool: 5
username: root
password:
host: localhost
Update
To use sqlite3, you need the sqlite gem and to set up your rails database.yml to use it. The default config rails generates uses sqlite and looks like this
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
to install, here are some good looking instructions
Related
Apologies for the rookie question. I would like to make postgresql my default for all new rails apps. I'm aware of the command:
rails new my_app --database=postgresql
...but I have an irrational dislike for sqlite3 and for typing this extra command. I want my rails apps to love postgres monogamously, without me telling them they shouldn't hook up with sqlite3 first. How do I go about this?
I use rbenv (again, irrationally) to manage my ruby versions. Thanks in advance.
Create a .railsrc file in your HOME directory and put your db override there
# ~/.railsrc
--database=postgresql
You can add all other overrides that you might want to use, like --skip-test-unit or the like.
This file will be applied each time you run a rails new command.
you can change default database by changing database.yml according to given file and don't forget to add pg gem in route gemfile like this gem 'pg'
development:
adapter: postgresql
encoding: utf8
database: project_development
pool: 5
username:
password:
test: &TEST
adapter: postgresql
encoding: utf8
database: project_test
pool: 5
username:
password:
production:
adapter: postgresql
encoding: utf8
database: project_production
pool: 5
username:
password:
if this did'nt help you see the rails cast Migrating to PostgreSQL
I want to migrate from sqlite3 to postgresql. After doing search I found that I should change my database.yml to somthing like that:
adapter: postgresql
encoding: unicode
database: [insert your dev database name]
pool: 5
username: [insert your user name]
password:
But I don't know what to provide in place of database, username and password. Because i don't remember creating any of them. I just created my rails app and migrations , and thats it.
To configure your rails project with postgres database
do the below steps.
provide your database details in the database.yml file
eg:
development:
username: postgres
database: ur-db-dev
password: pass
encoding: UTF8
adapter: postgresql
timeout: 500
pool: 5
add postgres gem in your Gemfile
gem 'pg'
then,
Do bundle install to install postgres gem
rake db:create to create your database
rake db:migrate to migrate your migration files
My ruby on rails app contains two database connection and its working good in localhost, but its not working on heroku. Getting this error
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/connection_specification.rb:52:in 'resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
database.yml
production:
adapter: mysql2
encoding: unicode
database: first_database
pool: 5
username: root
password:
production:
adapter: mysql2
encoding: unicode
database: second_database
pool: 5
username: root
password:
Since heroku overwrites default database.yml file, I followed this tutorial https://roratmindfiresolutions.wordpress.com/2013/05/27/connect-to-remote-database-server-from-heroku to setup multiple database connection on heroku, but still no change. I am using rails 4.0.1 . Any helps and suggestions are really appreciable. Thanks.
Note that in his YAML file he calls them production and production_sec whereas you're using production twice.
I'm trying to move my database to a PostgreSQL because I'm putting it up on Heroku.
Followed Railscast #342. Installed PostgreSLQ with its dependencies on my Ubuntu machine. When I installed it I think a user was created. I used this user in my database.yml. It looks like this:
production:
adapter: postgresql
encoding: unicode
database: dlrvbtApp1_production
pool: 5
username: jdartland
password:
development:
adapter: postgresql
encoding: unicode
database: dlrvbtApp1_development
pool: 5
username: jdartland
password:
test:
adapter: postgresql
encoding: unicode
database: dlrvbtApp1_test
pool: 5
username: jdartland
password:
Installed pg gem and the taps gem.
Ran a Bundle install, created the databases with rake db:create:all
Started the taps senatra server with taps server sqlite://db/development.sqlite3 jdartland secure
The server started. And tried to pull the SQL to my new development db through this command.
taps pull postgres://jdartland#localhost/dlrvbtApp1_development http://jdartland:secret#localhost:5000
I then get this error:
Failed to connect to database:
Sequel::DatabaseConnectionError -> PG::ConnectionBad: fe_sendauth: no password supplied
I have tried and tried, created new databases, canhing the .yml, pg_config and so on but I can't get it to work.
This is my first time working with PostgreSQL and Heroku, please give me a hand! :)
Change the user on production to localhost and leave the password blank.
production:
adapter: postgresql
encoding: unicode
database: dlrvbtApp1_production
pool: 5
username: localhost
password:
If you're moving your database to Heroku, the whole thing is just a case of connecting your DB to Heroku's PG one, and migrating the data.
Did you receive database details from Heroku?
They basically use Amazon to serve their DB's, and you'll get some credentials to put into your yml file for it. Here is an example of one of our live Heroku apps:
production:
adapter: postgresql
database: ********
pool: 5
username: ****************
password: ****************
port: 5432
host: ec2-54-228-234-250.eu-west-1.compute.amazonaws.com
Ways To Migrate To PostgreSQL (Heroku)
If you're looking to migrate your data from SQLite3 to PostgreSQL, I found a really good tutorial on how to do this here. Only problem is that it's not for SQLite lol
If you're trying to pull down your database from Heroku into a local postgres database, use pg:pull or pgbackups:
https://devcenter.heroku.com/articles/heroku-postgresql#pg-push-and-pg-pull
https://devcenter.heroku.com/articles/heroku-postgres-import-export
You should also look into using foreman and a .env file to setup your DATABASE_URL similar to how it's ran on Heroku, for dev/prod parity:
https://devcenter.heroku.com/articles/procfile#developing-locally-with-foreman
Got It working by following another post here on stack. Simply went up one directory, installed taps Gem install Taps. Uninstalled Rack gem gem uninstall rack 4 then Reinstalled it gem install rack --version 1.0.1. Did not do this in my progect directory, just simply in RVM. Then Pulled the database from the same directory. (not from my project directory).
Here is the Whole tread: taps migration failing from sqlite to postgres rails4, ruby 1.9.3
Hope it helps someone with the same problem.
Now just one thing left, Push it to heroku..... We'll see how that goes...hehe
Thanks for all help!
I made an app in Ruby on Rails and now I want to get it hosted. However, they require that I use MySQL and I set it up using sqLite3. Is there any way to convert it to use MySQL?
Step 0
To be safe, I recommend experimenting a bit with this technique in a virtual machine. Save yourself a bunch of heartache and build a virtual machine, check out your code, and have a safe playground that you can throw away if tragedy strikes.
Step 1
Make a backup copy of your database.yml file.
(from your application root)
cp config/database.yml config.database.yml.sqlite3
Step 2
Make a backup copy of your data
For Rails 3, install the YAML DB gem: https://github.com/ludicast/yaml_db
by running
gem install yaml_db
and then add to your Gemfile.
gem 'yaml_db'
For Rails 2.x install the YAML DB plugin:
script/plugin install git://github.com/adamwiggins/yaml_db.git
Run the dump task
rake db:dump
Step 3
Update your config/database.yml file. You will find entries like
development:
adapter: sqlite3
database: db/development.sqlite3
timeout: 5000
test:
adapter: sqlite3
database: db/test.sqlite3
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
timeout: 5000
Change them to
development:
adapter: mysql
encoding: utf8
reconnect: false
database: **myapp_development**
pool: 5
username: **root**
password: **supersecretpassword**
**socket: /opt/local/var/run/mysql5/mysqld.sock**
test:
adapter: mysql
encoding: utf8
reconnect: false
database: **myapp_test**
pool: 5
username: **root**
password: **supersecretpassword**
socket: **/opt/local/var/run/mysql5/mysqld.sock**
production:
adapter: mysql
encoding: utf8
reconnect: false
database: **myapp_production**
pool: 5
username: **root**
password: **supersecretpassword**
socket: **/opt/local/var/run/mysql5/mysqld.sock**
Be sure to update the values surrounded by asterix as appropriate for your platform! The socket value is only good for Mac OSX using MacPorts. Most flavors of linux do not require this value.
Step 5
If you have some errors in the following step, you might have to install the mysql or mysql2 gem:
sudo gem install mysql
or
sudo gem install mysql2
Have rake create your database
rake db:create
rake db:schema:load
Step 6
Use YamlDb to reload your data into MySql
rake db:load
As long as you have not written any SQL statements that run in sqlLite3 and not MySQL (which you won't have if all your database access is via ActiveRecord and ActiveRecord migrations) then all you need to do is change the database adapter in your database.yml config file.
Check Taps. I've successfully converted a Mysql database to Postgres with it --it should support SQLite.
Edit: Including working link from cony's comment here.
If there's no data to migrate, simply update database.yml and run 'rake db:schema:load' in the new environment. (NOT db:migrate which should only be used for incremental migrations!)
myproject user$ cd
user $ rails new myproject -d mysql
Say 'no' for all question but for Overwrite .../myproject/config/*database.yml*? (enter "h" for help) [Ynaqdh] say 'yes'.