Rake db:create is not working
The error says:
pg is not part of the bundle. Add it to your Gemfile.
To do so simply go to your Rails app directory and open the Gemfile
and place the following into it.
Example Config:
Gemfile:# Use PostgreSQL as the database for Active Record
gem 'pg'
database.ymldefault: &default
adapter: postgresql
encoding: unicode
pool: 5
username: postgres
password:
timeout: 5000
development:
<<: *default
database: myawesomeapp_dev
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: myawesomeapp_test
production:
<<: *default
database: myawesomeapp_prod
After you've added the line, save your file and hit bundle install
in your rails app directory to install the required gem.
Also be sure to have a user on your PostgreSQL instance which is allowed to connect
and to create
new databases. You don't need to create the databases by yourself.
Unable to create database with rake db:create command
Had this issue and never quite figured out why rails was doing this, but below should fix it.
- in terminal
psql template1
CREATE USER <username from config/database.yml if specified> with password '<password from config/database.yml if specified>';
ALTER USER <username ...> WITH SUPERUSER;
CREATE DATABASE chat_development WITH OWNER = '<username ...>';
CREATE DATABASE chat_test WITH OWNER = '<username ...>';
you don't need step 2/3, or the WITH OWNER = '<username>';
unless you specify a user/password in config/database.yml
.
Some common mistakes, pay close attention to where I have put single quotes, and don't forget the semi-colons!
Why is my rails db:create not working?
You just try this..
first of all you just check your gem
versions..
gem 'pg'
Then you can check your pg
username
and password
..
If you forgot your username
and password
don't worry :(..
You can change..
$ sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
//OR
$ sudo passwd postgres
Now can change your database.yml
development:
encoding: unicode
username: postgres
password: postgres
pool: 20
timeout: 5000
wait_timeout: 10
min_messages: warning
adapter: postgresql
host: localhost
database: auction_dev
port: 5432
If you got any other error let me know..
Error in rake db:create in new rails project
I simply reinstalled ruby+rails and things were alright.
I deleted the ~/.rbenv folder and ran sudo apt-get purge ruby
Then installed ruby and rails using Official Page.
Importantly, once I created a new project I was prompted to install another gem to resolve some dependency gem install rdoc-data
Issue with rake db:create
Unless you're running Rails 4.2.5 or higher, you'll want to put the following in your Gemfile
:
gem 'mysql2', '~> 0.3.10'
Source: mysql gem compatibility listing
Rails:: rake db:create does not return anything on Rails 3.0.3 and Ruby 1.9.2
After making Edit3, I realized that there might be something wrong with my own project in terms of required dependencies. During the course of installation, I faced many issues and to solve them, I tried every tip given on SO and other forums without knowing even if it's compatible with my existing installation or not. Initially I installed Ruby 1.8.7
and rails 3.1.x
without looking at Gemfile
, which as a newbie I didn't know its purpose. Then I installed Ruby 1.9.2
and started doing random installations.
And on them was installation of rake 10.0.2
while my project required rake 0.8.7
. Since I didn't know much about which rails server is compatible with which version of Ruby, I was trying installation whatever was given on internet, desperately wanting it to be working. Bad thing to do!!
Solution:
I uninstalled rake 10.0.2
and went back to rake 0.8.7
. This solution helped me to get it working. Uninstalled mysql (0.3.11)
and installed mysql2 (0.2.7)
Lesson learnt: Don't do random installations without looking at project requirements.
Error creating Rails DB using rake db:create
Thanks for all the help guys. Looks like the problem had to do with my install of the mysql gem under OSX.
@tim after I proceeded to the next step and got up and going I got an error on the console, so I did a bit of searching and found this helpful thread.
After I uninstalled my ruby gems gem uninstall mysql
I installed the proper mysql gems using this command (from the thread):
export ARCHFLAGS="-arch i386 -arch x86_64" ; gem install --no-rdoc --no-ri mysql -- --with-mysql-dir=/opt/local/lib/mysql5 --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config
After executing this one I was able to successfully run rake db:create
and proceed.
Thanks!!
Related Topics
Sublime Text 2 Doesn't Save Built SASS File
Understanding Ruby Method Parameters Syntax
Ruby: How to Remove Items from Array a If It's Not in Array B
Mongomapper Many to Many Issue with Array
PDF Generation Hangs Using PDFkit and Wkhtmotopdf
Ruby: How to Dynamically Replace Parameters in Native Pg Gem
Why Can't I Create Active Records That Count for Something in Rspec
What Ruby and Rails Developers Ought to Know
Difference Between Block and &Block in Ruby
Ruby - How to Retrieve Sum in Array Group by Multiple Keys with Condition Max
Why Does Shoveling a String into a Hash Cause This Result
Assets Precompiling Error with Jquery UI Plugin
How to Make Private Activities
Consolidating Duplicate Array Items
Rails Strong Params - Using Fields from Has_Many Object