rails g migration error - ruby-on-rails

I don't know what to do. Try to use command
$ rails g migration vacancy
but this command give me error:
invoke active_record
/home/proger/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych.rb:203:in `parse': (<unknown>): mapping values are not allowed in this context at line 21 column 11 (Psych::SyntaxError)
from /home/proger/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych.rb:203:in `parse_stream'
from /home/proger/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych.rb:151:in `parse'
...
There are many rows in error code
I don't know how to fix that Thanks
UPDATE
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: jobs
pool: 5
username: root
password: toor
socket: /var/run/mysqld/mysqld.sock
update:
with sqlite3 there is no problem. problem in mysql gem

It seems that you have syntax error in yaml file. Probably it is in config/database.yml

Related

How do I change rails' default database from sqlite3 to postgres, across all new projects?

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

$development_db_name$ does not exist error even after running db:create and db:migrate and getting report that they exist

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

Ruby On rails spree commerce installation

Hi friends am trying to bring spree commerce but i got error while am trying this command on windows 7 spree install
I got an error like this please help me ..
C:/Ruby193/lib/ruby/1.9.1/psych.rb:203:in `parse': (<unknown>): could not find
expected ':' while scanning a simple key at line 17 column 3 (Psych::SyntaxError)
should have single space after : in database.yml, for each line example
development:
adapter: mysql
encoding: utf8
reconnect: false
database: form_dev
pool: 5
username: user
password: password
host: localhost

Rake db error: ERROR 1102 (42000) at line 1: Incorrect database name [nil]

I am getting the following error:
$ rake db:drop
(in D:/Repository/MyApp)
~ [datamapper] Setting up the "development" environment:
~ [datamapper] Setting up :default repository: '' on mysql
ERROR 1102 (42000) at line 1: Incorrect database name ''
The following is my database.yml file:
defaults: &defaults
adapter: mysql
encoding: utf8
reconnect: false
pool: 5
username: dbuser
password: ******
development:
database: myapp_development
host: 127.0.0.1
<<: *defaults
test:
database: myapp_test
host: 127.0.0.1:3306
<<: *defaults
production:
database: myapp_production
host: mysql.myapp.com
<<: *defaults
I'm running a mysql 5.5 server on a Windows platform, with Ruby 1.9.2 and Rails 3, and the server is configured with the proper databases, user and password. I'm using datamapper. This works on our live site, but not on my local site. Running 'rails dbconsole' produces "ruby192installationpath/dbconsole.rb:75: in 'exec': can't convert nil into String (TypeError).
Has anyone run into this problem before? Any suggestions on how to diagnose or correct it? Or perhaps a simple diagnostic command that can be run from the terminal, rails or rake consoles to expose some information? Perhaps one that can verify it's connecting to the database, or if not what the problem is?
I was experiencing that same error and found through another post that it was actually caused by a YAML parsing error.
That made remember that when setting up Mongoid with Ruby 1.9.2, I had to include the following in config/environment.rb
#Add this to config/environment.rb at the top
require 'yaml'
YAML::ENGINE.yamler= 'syck'
That did the trick and solved this issue.
Hope it helps.

Convert a Ruby on Rails app from sqlite to MySQL?

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'.

Resources