Error: migrate SQLite to Postgres - ruby-on-rails-3

I developed my app with the standard configuration (SQLite 3). I want do deploy on heroku and have to change to postgresql.
But I get this error, when trying to migrate my db-schema.
rake db:migrate
rake aborted!
/Users/adrianschnell/Sites/bills_cmd/config/initializers/session_store.rb:3: syntax error, unexpected ':', expecting $end
...sion_store :cookie_store, key: '_bills_cmd_session'
^
/Library/Ruby/Gems/1.8/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
/Library/Ruby/Gems/1.8/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
/Library/Ruby/Gems/1.8/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
/Library/Ruby/Gems/1.8/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
/Library/Ruby/Gems/1.8/gems/railties-3.2.11/lib/rails/engine.rb:588
/Library/Ruby/Gems/1.8/gems/railties-3.2.11/lib/rails/engine.rb:587:in `each'
/Library/Ruby/Gems/1.8/gems/railties-3.2.11/lib/rails/engine.rb:587
/Library/Ruby/Gems/1.8/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `instance_exec'
/Library/Ruby/Gems/1.8/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `run'
/Library/Ruby/Gems/1.8/gems/railties-3.2.11/lib/rails/initializable.rb:55:in `run_initializers'
/Library/Ruby/Gems/1.8/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `each'
/Library/Ruby/Gems/1.8/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `run_initializers'
/Library/Ruby/Gems/1.8/gems/railties-3.2.11/lib/rails/application.rb:136:in `initialize!'
/Library/Ruby/Gems/1.8/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in `send'
/Library/Ruby/Gems/1.8/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/adrianschnell/Sites/bills_cmd/config/environment.rb:8
/Library/Ruby/Gems/1.8/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
/Library/Ruby/Gems/1.8/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
/Library/Ruby/Gems/1.8/gems/railties-3.2.11/lib/rails/application.rb:103:in `require_environment!'
/Library/Ruby/Gems/1.8/gems/railties-3.2.11/lib/rails/application.rb:297:in `initialize_tasks'
Tasks: TOP => db:migrate => environment
I don't know what i have to do now.
My Gem File has included 'pg' and my database.yml looks like:
# PostgreSQL v0.8.x
# gem install pg
development:
adapter: postgresql
encoding: unicode
database: bills_cmd_dev
pool: 5
username: adrianschnell
password:
# 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:
adapter: postgresql
encoding: unicode
database: bills_cmd_test
pool: 5
username: adrianschnell
password:
PostgreSQL is running - via terminal i can access it.
EDIT:
I noticed, that I get the following error when trying to create the postgre db:
rake db:create:all
rake aborted!
syntax error on line 18, col 11: `'
/Library/Ruby/Gems/1.8/gems/railties-3.2.11/lib/rails/application/configuration.rb:115:in `database_configuration'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.11/lib/active_record/railties/databases.rake:25
Tasks: TOP => db:create:all => db:load_config
(See full trace by running task with --trace)

after hours of searching and testing different suggestions, I tried the ones here: stackoverflow
especially the entry of Darren was the solution for me. Now my RoR App is running with postgre.

Related

error with rails server command

Can you point me to any good resources that show how to connect Sql Server to Rails app (Windows 7)?
I have done the following so far:
rails new simple_cms –d sqlserver
gem install bundle
rails s
after the last command, this error is thrown:
C:\Sites\s_cms>rails s
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.1.1/lib/active_support/core_ext/module/aliasing.rb:32:in `alias_method': undefined method `add_order!' for class `Class' (Name
Error)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.1.1/lib/active_support/core_ext/module/aliasing.rb:32:in `alias_method_chain'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/active_record/connection_adapters/sqlserver_adapter/core_ext/active_record.rb:14:in `singletonclass'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/active_record/connection_adapters/sqlserver_adapter/core_ext/active_record.rb:12:in `inc
luded'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/active_record/connection_adapters/sqlserver_adapter/core_ext/active_record.rb:145:in `in
clude'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/active_record/connection_adapters/sqlserver_adapter/core_ext/active_record.rb:145:in `<t
op (required)>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/active_record/connection_adapters/sqlserver_adapter.rb:3:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/active_record/connection_adapters/sqlserver_adapter.rb:3:in `<top (required)>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/activerecord-sqlserver-adapter.rb:1:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/activerecord-sqlserver-adapter.rb:1:in `<top (required)>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:76:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:72:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:72:in `block in require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:61:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:61:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler.rb:132:in `require'
from C:/Sites/s_cms/config/application.rb:7:in `<top (required)>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:79:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:79:in `block in server'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:76:in `tap'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:76:in `server'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
PS: If I use sqlite as a database system, I am able to successfully start the webserver (no error). This probably means there's nothing wrong with my rails installation. I am guessing I might need to add sth to database.yml or write the database user and password somewhere. But how come this is not required with sqlite3?
I also found this resource but not sure if still applicable (it refers to rails 2.0, whereas I use rails 4.1.1) http://rubyrailsandwindows.blogspot.de/2008/03/rails-2-and-sql-server-2008-on-windows_24.html - and some of the things there I tried but don't apply.
Thanks in advance.
Later edit: I also tried rails s after editing the database.yml (from the config folder) to contain:
development:
adapter: sqlserver
encoding: unicode
database: cms
pool: 5
username: guest1
password: pwd1234%^&^
test:
adapter: sqlserver
encoding: unicode
database: cms
pool: 5
username: guest1
password: pwd1234%^&^
production:
adapter: sqlserver
encoding: unicode
database: cms
pool: 5
username: guest1
password: pwd1234%^&^
(of course, I also created previously a db called cms, and added a user called guest1 with the specified password, then made sure teh credentials worked to connect to the db by mimic-ing network connection from my local Sql Server itself)
After this new action I get a similar error as above:
C:\Sites\simple_cms>rails s
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-.1.1/lib/active_support/core_ext/module/aliasing.rb:32:in `alias_method': undefined method `add_order!' for class `Class' (Name Error)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.1.1/lib/active_support/core_ext/module/aliasing.rb:32:in `alias_method_chain'
...............
This is a known bug with activerecord-sqlserver-adapter. It's being worked on but any fix has not yet been merged into a milestone.
It appears the workaround just now is to change your Gemfile to have:
gem 'activerecord-sqlserver-adapter', git: 'https://github.com/Desarrollo-CeSPI/activerecord-sqlserver-adapter.git'
Details of the issue are here and the efforts to fix it are here.

Impossible to use rake in my rails project

Every time I try to use rake in my rails project it throw me the message below. I tried to re-install ruby, rails, rake, re-create the project, launch my rake db:migrate with sudo but nothing seems to work...
I created the object via the scaffold command:
rails generate scaffold User nom:string email:string
After this command execute succesfully, i launch
rake db:migrate
And it return this message:
rake aborted!
GONE
/var/lib/gems/1.9.1/gems/railties-3.0.5/lib/rails/tasks/documentation.rake:1:in `require'
/var/lib/gems/1.9.1/gems/railties-3.0.5/lib/rails/tasks/documentation.rake:1:in `<top (required)>'
/var/lib/gems/1.9.1/gems/railties-3.0.5/lib/rails/tasks.rb:15:in `load'
/var/lib/gems/1.9.1/gems/railties-3.0.5/lib/rails/tasks.rb:15:in `block in <top (required)>'
/var/lib/gems/1.9.1/gems/railties-3.0.5/lib/rails/tasks.rb:6:in `each'
/var/lib/gems/1.9.1/gems/railties-3.0.5/lib/rails/tasks.rb:6:in `<top (required)>'
/var/lib/gems/1.9.1/gems/railties-3.0.5/lib/rails/application.rb:213:in `require'
/var/lib/gems/1.9.1/gems/railties-3.0.5/lib/rails/application.rb:213:in `initialize_tasks'
/var/lib/gems/1.9.1/gems/railties-3.0.5/lib/rails/application.rb:139:in `load_tasks'
/var/lib/gems/1.9.1/gems/railties-3.0.5/lib/rails/application.rb:77:in `method_missing'
/home/bassochette/Dev/rails/tuto/demo_app/Rakefile:7:in `<top (required)>'
(See full trace by running task with --trace)
ps: I'm new to rails and in the learning phase.

Rails server not starting. Gems all installed, I'm confused

I went to restart my rails server today and when I went to fire it back up here's the error I got. I've tried everything and haven't been able to crack it. I uninstalled and reinstalled activesupport 3.1.0, and it seems like there's an error in activesupport itself, which I doubt I can fix. So, color me confused (paint me perplexed). Any advice much appreciated.
$ RESQUE_INTERFACE=true rails s
=> Booting WEBrick
=> Rails 3.1.0 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Library/Ruby/Gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `load': /Users/nickgoddard/codebase/newshop/config/initializers/session_store.rb:3: syntax error, unexpected ':', expecting $end (SyntaxError)
...sion_store :cookie_store, key: '_newshop_session'
^
from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `load'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `load_dependency'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:640:in `new_constants_in'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `load_dependency'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `load'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.0/lib/rails/engine.rb:555
from /Library/Ruby/Gems/1.8/gems/railties-3.1.0/lib/rails/engine.rb:554:in `each'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.0/lib/rails/engine.rb:554
from /Library/Ruby/Gems/1.8/gems/railties-3.1.0/lib/rails/initializable.rb:25:in `instance_exec'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.0/lib/rails/initializable.rb:25:in `run'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.0/lib/rails/initializable.rb:50:in `run_initializers'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.0/lib/rails/initializable.rb:49:in `each'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.0/lib/rails/initializable.rb:49:in `run_initializers'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.0/lib/rails/application.rb:92:in `initialize!'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.0/lib/rails/railtie/configurable.rb:30:in `send'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/nickgoddard/codebase/newshop/config/environment.rb:5
from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `load_dependency'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:640:in `new_constants_in'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `load_dependency'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'
from /Users/nickgoddard/codebase/newshop/config.ru:4
from /Library/Ruby/Gems/1.8/gems/rack-1.3.6/lib/rack/builder.rb:51:in `instance_eval'
from /Library/Ruby/Gems/1.8/gems/rack-1.3.6/lib/rack/builder.rb:51:in `initialize'
from /Users/nickgoddard/codebase/newshop/config.ru:1:in `new'
from /Users/nickgoddard/codebase/newshop/config.ru:1
You're trying to run Ruby 1.9 code on Ruby 1.8, specifically the session_store hash parameters.
Usually, when you create a new Rails app, it should know this, but I'm not sure of the specifics about how you set up your app (or maybe you cloned someone else's?). To create an app and force it to use the 1.8 style of hashes, do:
rails new my_app --old-style-hash
Or, you can use something like rvm or rbenv to install Ruby 1.9 and use that instead.

"\xC4" from ASCII-8BIT to UTF-8 when running rake db:migrate on Heroku

When I try to run heroku run rake db:migrate in my application, I get the following error
"\xC4" from ASCII-8BIT to UTF-8
with a stacktrace of
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:150:in `write'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:150:in `puts'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:150:in `display_error_message'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:142:in `rescue in standard_exception_handling'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:132:in `standard_exception_handling'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `'
/app/.bundle/gems/ruby/1.9.1/bin/rake:19:in `load'
/app/.bundle/gems/ruby/1.9.1/bin/rake:19:in `'
I've tried setting encoding manually in config/environment.rb via
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
But it doesn't seem to help. The problem might be, that I'm using slim as a templating engine with many unicode characters directly in the templates, but I'm not sure if there's a better way of doing that.
Simply add this to the top of your file
# encoding: UTF-8
this error is frequent with migration when you insert data. For exemple I've got this with a simple migration adding Québec
Province.create(:name => 'Québec (Canada)')

rake db:migrate aborted! on US-ASCII using rake 0.9.2.2 and rails 3.0.10

Recently I upgraded my gems and started adding new stuff to my app like authentication by third party social websites using omniauth gem. On development environment everything is fine and works like a charm.
I am deploying to staging and production servers using capistrano. Basic deployment is fine and working so far, but I have got really strange problems when I want to do migrations when deploying.
I get the following error messages from capistrano:
[my.server.com] executing command
*** [err :: my.server.com] rake aborted!
*** [err :: my.server.com] "\xC5" on US-ASCII
*** [err :: my.server.com]
*** [err :: my.server.com] (See full trace by running task with --trace)
command finished in 2472ms
I was googling all around and couldn't find any relevant solution. I also tried to downgrade rake gem back to 0.8.7 but with no success on the end - the same errors.
After hours of googling and digging in I found the solution that (I hope) may by helpful for someone with a similar or the same problem.
I did bundle exec rake --trace db:migrate on the staging server and got the following error messages:
rake aborted!
"\xC5" on US-ASCII
/var/www/myapp/test.myapp.com/releases/20111230233802/config/application.rb:5:in `read'
/var/www/myapp/test.myapp.com/releases/20111230233802/config/application.rb:5:in `<top (required)>'
/var/www/myapp/test.myapp.com/releases/20111230233802/Rakefile:4:in `require'
/var/www/myapp/test.myapp.com/releases/20111230233802/Rakefile:4:in `<top (required)>'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:501:in `raw_load_rakefile'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `block in load_rakefile'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `block in run'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/bin/rake:19:in `load'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/bin/rake:19:in `<main>'
So I jumped in to the config/application.rb file to find out what could rise the error. Line 5 of that file loads an external config file:
require 'yaml'
APP_CONFIG = YAML.load(File.read(File.expand_path('../app_config.yml', __FILE__)))
and that external file contains UTF-8 chars, not US-ASCII. So I tried a couple of different solutions to solve that problem.
The only one which worked for me was to add an extra few lines of code on top of config/application.rb file:
if RUBY_VERSION =~ /1.9/
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
end
just to tell rake to load external files using utf-8 encoding. After that change everything went smooth and exactly as expected. Problem solved!
PS.
I really don't know why developers of rake 0.9 have changed previous behavior of rake 0.8 which worked fine for me and probably for you as well for a long time. Maybe you have an idea why? I am very curious.