So after having a problem deploying to Heroku for the first time, I wanted to get my dev environment running Postgres..
That's when i couldn't get my dev environment working. My errors lie in the database. I'm running Rails 3.2, Postgres.app, I got a database setup, I think database.yml is good to go.
As far as I can tell, my schema.rb is blank. It originally was not. When i delete it and reset the database, the new schema.rb is still blank. Where does schema get it's information from?
Rake db:migrate returns this SELECT "schema_migrations"."version" FROM "schema_migrations"
The rails s error complains about the lack of a users table.. doh.
I admittedly edited the schema.rb early on when i was first starting. But I don't know what caused this sort of reset.
database.yml
development:
adapter: postgresql
database: phriends
encoding: utf8
username: mrbubbles
password:
test:
adapter: postgresql
database: test
encoding: utf8
username: mrbubbles
password:
production:
adapter: postgresql
database: production_database
encoding: utf8
username: mrbubbles
password:
Sounds like you didn't rake db:setup, db:setup will
Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first)
Note the "load the schema" part, that would read schema.rb and build the tables based on what it says. So restore your schema.rb and do a db:setup.
Related
I have been using sqlite for my project,
made alot of changes in migration files, I want to upload to heroku, but it does not support sqlite, so I decided to change it to pg.
I changed the database.yml file to the right values, I try to migrate the database, but I get tons of errors of migration, where I decided backthen to remove a column, but it doesn't exist anymore.
Is there anyhow to create a migration file out of the current fine working database in sqlite, that will be put in one migration file to be migrated in pg version ?
This is an example of the configuration of a test database, actually it can be production or development if you want:
test:
adapter: mysql2
database: redmine_test
host: localhost
username: 'user'
password: 'password'
port: 3306
reconnect: true
encoding: utf8
test_sqlite3:
adapter: sqlite3
database: db/test.db
test_pgsql:
adapter: postgresql
database: redmine_development
host: localhost
username: user
password: 'password'
When you use rake db:migrate it will try to execute the migrations for all of your environments, this is Production/Development/Test.
If you want to specify the environment use this command instead:
rake db:migrate RAILS_ENV=NameOfTheEnviroment
I experimented a few weeks ago by adding a second database to my database.yml. While everything worked, I didn't like the approach and removed all the models etc of that second DB. The primary database was postgresql and the second was sqlite3. The db location was the absolute path to the sqlite3 db in database.yml.
Every once in a while I will dump my production db on the server and pull it into my development db. I'd do this with:
rake db:drop
rake db:create
psql -d {database} < {output from pg_dump}
The first time I tried this procedure after my experiment, I got a rake error:
xuserAir:db xuser$ rake db:create
(in /Users/xuser/Work/v/vfw-post)
/Users/xuser/vfw/gnucash/export/vfwexport.gnucash already exists
vfw-post_test already exists
rake aborted!
Gem::LoadError: Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
Gem::LoadError: sqlite3 is not part of the bundle. Add it to Gemfile.
There is no reference anywhere in my application root to sqlite3, the database path or any of the file names or directory. rake db seems to be picking up the old information from someplace by I have no idea where. I may have had db/development.db set up as a symbolic like to the export.db, but that is also gone.
Also rake db:drop deleted the sqlite3 database that was outside the app root.
I striped everything in my database.yml file:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: vfw-post_development
test:
<<: *default
database: vfw-post_test
production:
<<: *default
database: vfw-post_production
username: vfw
# password: <%= ENV['VFW-POST_DATABASE_PASSWORD'] %>
And still get the same error.
Stuck
Rails 4.2
I found out where it was coming from.
Somewhere in my experiment with two database I set up
DATABASE_URL=sqlite3:/Users/xuser/vfw/gnucash/export/vfwexport.gnucash
I think to help when I deployed. I didn't remove that and it goes to the DATABASE_URL first.
So I seemingly successfully installed postgres for production for heroku deployment, but locally rails seems to not find/nor create the database.
When I go to localhost:3000 I get the error:
ActiveRecord::NoDatabaseError
FATAL: database "dimension_development" does not exist Run `$ bin/rake db:create db:migrate` to create your database
When I run $bin/rake db:create I get:
~ already exists
Then, run db:migrate and restart the rails server, reload the page, and get same error.
So I tried instead to run $bin/rake db:create:all and got:
~ already exists
dimension_test already exists
dimension_production already exists
Then did db:migrate again but nothing changed.
If they already exist, why isn't rails finding them? I notice that in the config/db folder there is still the old development.sqlite3 file but no postgres file.
Any idea what could be going on to cause this error?
My database.yml is:
development:
adapter: postgresql
database: dimension_development
pool: 5
timeout: 5000
test:
adapter: postgresql
database: dimension_test
pool: 5
timeout: 5000
production:
adapter: postgresql
database: dimension_production
pool: 5
timeout: 5000
Thanks! This has got me stumped and I haven't been able to find anything on stackoverflow dealing with this pitfall.
In case of postgresql you will not find any file like development.sqlite3. It's in case of sqlite only.
You did not provided database credential in your database.yml file might causing this error. Try pass username and password as well.
development:
adapter: postgresql
database: dimension_development
pool: 5
timeout: 5000
username: xxxx
password: xxxx
I recently switched to postgres for a rails app in development since I deployed on Heroku and want to match production. Postgres is installed and working correctly for my application when I set the database name equal to 'postgres', which is the default name from what I understand.
However, I would like to change the database name for development, test and production. If I simply change the names in database.yml, and try to run a rake task, I get the following error in my terminal:
NOTICE: database "something_development" does not exist, skipping
Couldn't drop something_test : #<PG::Error: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?>
rake aborted!
FATAL: database "something_development" does not exist
Here is what my database.yml file currently looks:
development:
adapter: postgresql
host: localhost
database: something_development
username: name
test:
adapter: postgresql
database: something_test
pool: 5
timeout: 5000
production:
adapter: postgresql
host: localhost
username: name
database: something_production
Are there some other steps I am missing? Apologies if I am missing something obvious here! Thanks!
Changing the name in the database.yml file only changes the place that it looks for the database, it does not actually rename the database itself. If you change the specified location, you will need to rename the database to match, using a GUI tool (like navicat or pgadmin) or the command line.
Also, it is probably an obfuscation omission, but your posted output refers to both shredset_development and something_development. If this continues to fail, perhaps verify that all of your names are the same everywhere...
Weird error. All help appreciated.
Here's my database.yml
development:
adapter: postgresql
encoding: unicode
database: app_development
pool: 5
username: username
password:
test:
adapter: postgresql
encoding: unicode
database: app_test
pool: 5
username: username
password:
production:
adapter: postgresql
encoding: unicode
database: app_production
pool: 5
username: username
password:
When I create the databases manually and try to use them, for example rake db:test:preare I get the following error:
FATAL: database "postgres" does not exist
When I try to drop the databases I get the following errors:
Couldn't drop app_development : #<PG::Error: FATAL: database "postgres" does not exist
>
Couldn't drop app_test : #<PG::Error: FATAL: database "postgres" does not exist
>
Couldn't drop app_production : #<PG::Error: FATAL: database "postgres" does not exist
If I try to create the databases through with rake db:create:all I get the following errors:
app_development already exists
app_test already exists
app_production already exists
So it appears that my database.yml is ok. But for some reason it's looking for a database called postgres when that's not what's in my database.yml.
Any help appreciated.
EDIT:
Here is more from the trace of rake:
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"app_production", "pool"=>5, "username"=>"username", "password"=>nil}
[Mac OS X] I've never had any problem with PostGreSQL while using Linux. However, I started working with a MacBook and got the same error as you. So... Probably this is not the solution you were expecting for, but this one app solved all my headaches. I just wanted to share it with you guys.
http://postgresapp.com/
You've not said whether you actually have a postgres database, which is what the error is complaining about.
Presumably not, and this "rake" tool is connecting as user postgres to database postgres so it can create the new databases. Obviously it needs to connect as someone to do anything.
Do take the time to skim through the PostgreSQL manuals and understand how to enable/control logging. It'll serve you well in the long run. I'm guessing there is a debug/log setting for rake/rails too.
I'm using Mac OS X, I had the same problem with python and sqlalchemy.
Just like Flavio suggested, check postgresapp and check How to connect section.
from sqlalchemy import create_engine
engine = create_engine('postgresql://localhost/[YOUR_DATABASE_NAME]')