0

I previously was making some webapps using Spring MVC + PostgreSQL on my PC.

Wanted to try RoR, faced strange prob with DB connection, google isn't helping.

I created i new Rails web-application, made one model and tried to make a migration. (Last Rails gem, 5.0.0.beta3)

The problem is:

When i'm running db:migrate/create/drop Rails is trying to manipulate my existing DB's instead of creation new ones.

-i have a few PostgreSQL databases on my local PostgreSQL server, which i still want to keep active on it. Lets say 'XXXXXXX', 'YYYYYYYYY', 'ZZZZZZZZZ'

Once i run db:create i get the following log:

C:\Users\****\RubymineProjects\sample_articles>rails db:create
'XXXXXXX' already exists

DB migrate is executed successfully and also creating one additional database 'sample_articles_development', which is the name as i specify in my database.yml. BUT the new tables appears to my existed database 'XXXXXXX'(which i didn't configure in any configs).

This is my database.yml config:

default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see rails configuration guide
  # http://guides.rubyonrails.org/configuring.html#database-pooling
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: sample_articles_development
  username: rails
  password: *******
  host: localhost
  port: 5432

test:
  <<: *default
  database: sample_articles_test

production:
  <<: *default
  database: sample_articles_production
  username: sample_articles
  password: <%= ENV['SAMPLE_ARTICLES_DATABASE_PASSWORD'] %>
4
  • Only rake db:create will try to create a new database. rake db:migrate will use an existing one (which it reads from database.yml). You refer to calling rake db:create as "doing a migration". it isn't - you're just confusing things. Commented Apr 12, 2016 at 11:27
  • Ok. Maybe confusing. I'm completely new to Rails. Ok, lets say the problem is in db:migrate. But still the prob is that i can't understand why does it use one of my existing DB's Commented Apr 12, 2016 at 11:30
  • Well then your question becomes "When i'm running db:migrate Rails is trying to manipulate my existing DB's", and this is the expected behaviour, so there's nothing wrong. Commented Apr 12, 2016 at 11:31
  • why is this expected behavior? i do set a DB name in my database.yml Commented Apr 12, 2016 at 11:32

1 Answer 1

1

You likely have a $DATABASE_URL variable in your environment. That will override the value in database.yml.

unset DATABASE_URL
Sign up to request clarification or add additional context in comments.

1 Comment

Yep, that was the problem. Thank you, didn't thought about this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.