Rails migration stops & hangs - ruby-on-rails

I have the following migration:
class AddHyphenatedNameToMenus < ActiveRecord::Migration
def up
add_column :menus, :hyphenated_name, :string, null: false, required: true
end
def down
remove_column :menus, :hyphenated_name
end
end
The rails migration stops mysteriously and hangs.
$ rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
== AddHyphenatedNameToMenus: migrating =======================================
-- add_column(:menus, :hyphenated_name, :string, {:null=>false, :required=>true})
On pressing 'ctrl+c' I get the following error trace:
undefined method `result' for Interrupt:Interrupt/home/.rvm/gems/ruby-1.9.3-p194#abc/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1147:in `translate_exception'
I am unable to find the reason for the same. Any help would be much appreciated. Thanks.

Related

When rollbacking a migration in rails I get NoMethodError: undefined method `trim' for LL():Rake::Scope::EmptyScope

When I rollback migrations in rails I get the error:
NoMethodError: undefined method `trim' for LL():Rake::Scope::EmptyScope
The migration goes through but it prevents me from running multiple migrations as it crashes after rollbacking.
Here is stack trace:
>> rails db:rollback ^2 --trace
** Invoke db:rollback (first_time)
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:load_config
** Execute multiverse:load_config
** Execute db:rollback
== 20201007084505 CreateValuation: reverting ==================================
-- drop_table(:valuations)
-> 0.0030s
== 20201007084505 CreateValuation: reverted (0.0080s) =========================
** Invoke db:_dump (first_time)
** Execute db:_dump
** Invoke db:schema:dump (first_time)
** Invoke db:load_config
** Execute db:schema:dump
rails aborted!
NoMethodError: undefined method `trim' for LL():Rake::Scope::EmptyScope
Any ideas? I don't even know where to start.
EDIT:
Migrations code per request.
class CreateValuation < ActiveRecord::Migration[5.2]
def change
create_table :valuations do |t|
t.integer :car_id, null: false
t.integer :value
t.datetime :date, null: false
t.timestamps
end
end
end

Problems with migration of Cassandra db on Ubuntu 14.04

When I making migration db Cassandra with command:
es#es:~/server-new$ rake ks2:migrate_old
After this I get error:
rake aborted!
SystemStackError: stack level too deep
Tasks: TOP => ks2:migrate_old => ks2:set_keyspace2 => ks2:configure2 => environment
(See full trace by running task with --trace)
When I start command: rake ks2:migrate_old --trace
I get error:
** Invoke ks2:migrate_old (first_time)
** Invoke ks2:set_keyspace2 (first_time)
** Invoke ks2:configure2 (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
SystemStackError: stack level too deep
/home/es/.rvm/gems/ruby-2.0.0-p353/gems/rake-10.4.2/lib/rake/task.rb:183
Tasks: TOP => ks2:migrate_old => ks2:set_keyspace2 => ks2:configure2 => environment
How to make migration work?

"NoMethodError: undefined method `type' for "character varying":String" after "rake db:migrate"

I tried to add check-ins to micro-posts but I've got an error after rake db:migrate.. What does it mean?
Error
$ rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
rake aborted!
NoMethodError: undefined method `type' for "character varying":String
add_checkin_to_microposts
class AddCheckinToMicroposts < ActiveRecord::Migration
def change
add_column :microposts, :location, :point, :geographic => true
end
end
database.yml
development:
adapter: postgresql
schema_search_path: public, postgis
encoding: unicode
database: blog_development
host: localhost
pool: 5
username: ********
password:
Assuming you are using the gem activerecord-postgis-adapter, you'd better try to change the database adapter to postgis as recommended in their official document:
https://github.com/rgeo/activerecord-postgis-adapter
the problem that you are having is that point method does not exist in ActiveRecord.
Instantiates a new column for the table. The type parameter is normally one of the migrations native types, which is one of the following: :primary_key, :string, :text, :integer, :float, :decimal, :datetime, :time, :date, :binary, :boolean.
For more info pleas read http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html#method-i-column
Hope this helps

rake db:create gives undefined method `[]' for nil:NilClass error

Postgres 9.3, Ruby 2.1.0
rake db:create isn't making a test database. I already have a production database. I tried using RAILS_ENV=test rake db:create to force it but it returns "test database is not configured.
My database.yml ->
development:
adapter: postgresql
  database: app_prod
  host: localhost
test: &test
  adapter: postgresql
  database: app_test
  host: localhost
cucumber:
<<: *test
production:
  adapter: postgresql
 database: app_prod
  host: localhost
So it is configured. I also tried just using a console createdb app_test to create my test database but I receive the same error when I try to run rake db:test:prepare.
Anyone have any ideas?
this is --trace on db:create:all
** Invoke db:create:all (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:create:all
rake aborted!
undefined method `[]' for nil:NilClass
/Users/username/.rvm/rubies/ruby-2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.3/lib/active_record/tasks/database_tasks.rb:189:in `block in each_local_configuration'
this is trace on db:test:prepare
** Invoke db:test:prepare (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config
** Execute db:test:purge
rake aborted!
undefined method `[]' for nil:NilClass
/Users/username/.rvm/rubies/ruby-2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.3/lib/active_record/tasks/database_tasks.rb:137:in `purge'
Try running this in console
ActiveRecord::Base.configurations
You should get your database configurations.
Line 3 in this method(Line 189 in github) is failing in your case because configuration is nil
def each_local_configuration
ActiveRecord::Base.configurations.each_value do |configuration|
next unless configuration['database']
if local_database?(configuration)
yield configuration
else
$stderr.puts "This task only modifies local databases. #{configuration['database']} is on a remote host."
end
end
end

What would cause this migration to hang?

I'm trying to upgrade an old 1.2.6 Rails application to 2.3.8, and I'm running into a bit of a snag with migrations. Namely, if I have something like ModelName.create(:foo => "bar") in the migration, the migration doesn't complete. It doesn't hit an infinite loop or anything. It just refuses to complete that migration.
Here's some sample code.
This works:
class CreateNewsArticles < ActiveRecord::Migration
def self.up
create_table :news_articles, :force => true do |t|
t.string "name"
t.string "image"
t.text "body"
t.boolean "featured", :default => "0"
t.integer "position"
t.timestamps
end
# Section.create(:name => 'News Articles', :controller => 'news_articles', :description => 'Add, edit, and delete news articles.')
end
def self.down
drop_table :news_articles
Section.find_by_name('News Articles').destroy
end
end
Uncommenting the Section.create(...) means the migration never completes.
Here's the output from rake db:migrate --trace:
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
== CreateNewsArticles: migrating =============================================
-- create_table(:news_articles, {:force=>true})
-> 0.0531s
And after commenting out the Section.create
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
== CreateNewsArticles: migrating =============================================
-- create_table(:news_articles, {:force=>true})
-> 0.0479s
== CreateNewsArticles: migrated (0.0481s) ====================================
** Invoke db:schema:dump (first_time)
** Invoke environment
** Execute db:schema:dump
I've tried this on another computer, and it works. Same version of rake, same version of ruby, and rails is frozen.
rake --VERSION: rake, version 0.8.7, ruby -v: ruby 1.8.6 (2010-02-05 patchlevel 399) [i686-darwin10.3.0], rails -v: Rails 2.3.8
Anyone have any ideas?
You can see the same symptom from a different cause: a migration can hang if you are running:
$ rails console --sandbox
in another process. Quitting the console process allows the migration to complete.
I had same problem .. I found out that there was idle transaction which blocked further queries on this table ..
Run:
heroku pg:ps
To view database processes. You will have to kill idle process:
heroku pg:kill 913 --force -a
(913 is ID of idle process -> change it to your needs
Apparently using ruby 1.8.6-p399 was the culprit. Switching to 1.8.6-p369 solved it.
You might also try defining a bar-bones section model in the migration.

Resources