I've got a model, say User, and a model Admin which inherits from User. I have some code in lib folder which uses those two models. But if I install a new database and try to run the migrations rails crashes saying that there is no such model as User. Are there any best practices to bypass this error?
`Mysql2::Error: Table 'testing_interface_development.users' doesn't exist: SHOW FULL FIELDS FROM `users`
/home/arthurborisow/Programming/my_project/test_interface/lib/active_record/timed_out_queries_hotfix.rb:9:in `query'
/home/arthurborisow/Programming/my_project/test_interface/lib/active_record/timed_out_queries_hotfix.rb:9:in `query_with_reconnect'
/home/arthurborisow/Programming/my_project/test_interface/lib/active_record/timed_out_queries_hotfix.rb:31:in `block in execute'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activesupport-3.2.11/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/home/arthurborisow/Programming/my_project/test_interface/lib/active_record/timed_out_queries_hotfix.rb:31:in `execute'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:259:in `execute_and_free'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:426:in `columns'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/model_schema.rb:228:in `yield'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/model_schema.rb:228:in `columns'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/model_schema.rb:237:in `columns_hash'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/inheritance.rb:19:in `descends_from_active_record?'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/inheritance.rb:25:in `finder_needs_type_condition?'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/base.rb:455:in `relation'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/scoping/named.rb:37:in `scoped'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/querying.rb:9:in `where'
/home/arthurborisow/Programming/my_project/test_interface/app/models/admin.rb:15:in `<class:Admin>'
/home/arthurborisow/Programming/my_project/test_interface/app/models/admin.rb:1:in `<top (required)>'`
When setting up a completely fresh database (instead of upgrading your existing one), it is better to use rake db:setup to load the schema.rb file instead of running each migration in succession. This question explains the various db Rake tasks pretty well:
Difference between rake db:migrate db:reset and db:schema:load
rake db:setup
Is the best option also,
You can also specify your migration version which do you want to migrate using below command:
rake db:migrate:up VERSION=20080906120000
Related
I am a new ROR developer. We are developing an application using Rails and AngularJS. A brief background of what I was trying to do:
Another developer developed an application (partial) named hiredjob. I have to continue development with his application changing the name of the application to hiredtoday and also changing all the models from admin_X to X . For that following is the sequence of steps I follow:
Method 1:
Copy the old hiredjob application to a new application hiredtoday.
Delete all db/migrate.
rails generate devise admin.
rake db:migrate gives error
Error from rake db:migrate:
home/arshi/.rvm/gems/ruby-2.2.3/gems/devise-
3.5.2/lib/devise/rails/routes.rb:485:in `raise_no_devise_method_error!': Admin does not respond to 'devise' method. This usually means you haven't loaded your ORM file or it's being loaded too late. To fix it, be sure to require 'devise/orm/YOUR_ORM' inside 'config/initializers/devise.rb' or before your application definition in 'config/application.rb' (RuntimeError)
On searching solution for above on the internet, I comment devise_for :admins in config/route.rb
After which on running rake db:migrate again I got an error.
Error is as follow:
StandardError: An error has occurred, all later migrations canceled:
Mysql2::Error: Table 'hiredjob_development.admins' doesn't exist: ALTER TABLE 'admins' ADD 'email' varchar(255) DEFAULT '' NOT NULL/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:305:in `query'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:305:in `block in execute'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_adapter.rb:473:in `block in log'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activesupport-4.2.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_adapter.rb:467:in `log'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:305:in `execute'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/mysql2_adapter.rb:231:in `execute'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:393:in `add_column'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:573:in `block (3 levels) in <class:Table>'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:572:in `each'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:572:in `block (2 levels) in <class:Table>'
Note: I have also tried to do run: rake db:drop db:create db:migrate. But still does not work.
i think you are getting this error because devise depends on the table already having been created. you need to:
1) delete the devise migration
2) write a migration to create the admins table http://guides.rubyonrails.org/active_record_migrations.html#creating-a-table
3) regenerate the devise migration.
Some of my rSpec tests are failing and I suspect it's due to the test database not being cleared out. When I try to run rake db:test:prepare, I'm getting the error below (i'm in Rails 3.2). Clearly, this looks like some kind of Postgres issue, looks like the rake task is trying to drop the test database so it can repopulate it. Production database schema loads fine.
I've looked for the rake task in lib/tasks/ but I haven't been able to find it. Anyone have any idea on what's going on?
osx_user-> rake db:test:prepare
[RailsAdmin] RailsAdmin initialization disabled by default. Pass SKIP_RAILS_ADMIN_INITIALIZER=false if you need it.
rake aborted!
ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: zero-length delimited identifier at or near """"
LINE 1: DROP DATABASE IF EXISTS ""
^
: DROP DATABASE IF EXISTS ""
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `async_exec'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `block in execute'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-3.2.14/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:649:in `execute'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:772:in `drop_database'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:623:in `drop_database'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:532:in `block (3 levels) in <top (required)>'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:559:in `block (3 levels) in <top (required)>'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/bin/ruby_executable_hooks:15:in `eval'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:test:load => db:test:purge
(See full trace by running task with --trace)
Figured it out. My database.yml file for the development environment was set like this:
database: <%= ENV['DATABASE_NAME_TEST'] %>
The rake task was looking for an environmental variable that did not exist.
I had already ran "$rails generate paperclip pin image" but decided to reinstall it to attempt to resolve "Could Not Run The Identify Command. Please Install ImageMagick." error while uploading image.
Thus went to terminal and ran "$ rails generate paperclip pin image --force" but ran into a problem I cant resolve. Pls help!
Steven-Lims-MacBook-Pro:Pinteresting stevenlim$ rake db:migrate
== AddAttachmentImageToPins: migrating =======================================
-- change_table(:pins)
rake aborted!
An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: duplicate column name: image_file_name: ALTER TABLE "pins" ADD "image_file_name" varchar(255)/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in `initialize'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in `new'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in `prepare'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:134:in `execute'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:331:in `block in execute'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:435:in `block in log'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:430:in `log'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:331:in `execute'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/schema_statements.rb:360:in `add_column'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:454:in `add_column'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/schema_definitions.rb:360:in `column'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/paperclip-3.5.4/lib/paperclip/schema.rb:52:in `block (2 levels) in attachment'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/paperclip-3.5.4/lib/paperclip/schema.rb:51:in `each_pair'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/paperclip-3.5.4/lib/paperclip/schema.rb:51:in `block in attachment'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/paperclip-3.5.4/lib/paperclip/schema.rb:50:in `each'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/paperclip-3.5.4/lib/paperclip/schema.rb:50:in `attachment'
/Users/stevenlim/Desktop/pinteresting/db/migrate/20140216024257_add_attachment_image_to_pins.rb:4:in `block in up'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/schema_statements.rb:334:in `change_table'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:625:in `block in method_missing'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:597:in `block in say_with_time'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:597:in `say_with_time'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:617:in `method_missing'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:383:in `method_missing'
/Users/stevenlim/Desktop/pinteresting/db/migrate/20140216024257_add_attachment_image_to_pins.rb:3:in `up'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:534:in `up'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:574:in `exec_migration'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:555:in `block (2 levels) in migrate'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:554:in `block in migrate'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:553:in `migrate'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:709:in `migrate'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:959:in `block in execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:1005:in `block in ddl_transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/transactions.rb:209:in `transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:1005:in `ddl_transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:958:in `execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:920:in `block in migrate'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:916:in `each'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:916:in `migrate'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:764:in `up'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:742:in `migrate'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
STATUS
Steven-Lims-MacBook-Pro:Pinteresting stevenlim$ rake db:migrate:status
database: /Users/stevenlim/Desktop/pinteresting/db/development.sqlite3
Status Migration ID Migration Name
--------------------------------------------------
up 20140205132449 Devise create users
up 20140210143217 Create pins
up 20140212145812 Add user id to pins
up 20140215161350 ********** NO FILE **********
down 20140216134900 Add attachment image to pins
ImageMagick is a prerequisite for Paperclip gem. Paperclip would work only if ImageMagick is installed on your system and Paperclip has access to it. Looking at your error "Could Not Run The Identify Command. Please Install ImageMagick." it seems like ImageMagick is not installed on your system. First step is to install it or check if it's installed then in your environment config file, let Paperclip know where to look for ImageMagick by adding ImageMagick path to it.
For eg:
In development mode, you might add this line to config/environments/development.rb
Paperclip.options[:command_path] = write_your_imagemagick_path
Where
You can get ImageMagick path by running which convert
Looking at the second error which you got, it seems like you already ran the migration once before, hence, the paperclip attachment related fields like image_file_name are already created in database table pins. And as you are trying to run that migration again you are getting duplicate column name error.
EDIT:
When you generated the paperclip pin image for the first time, one migration file was created under db/migrations which looking at the error I am assuming that you ran using rake db:migrate which is why you already have Paperclip image related columns in your pins table.
Later when you generated the paperclip pin image for the second time another migration file is created with the same column names which when you run using rake db:migrate is obviously going to yield duplicate column error.
You can just delete this second migration file, you don't need to run it as the columns are already created in database.
BUT if you still want to run the second migration file itself then first do rake db:rollback till the step where you ran the first migration so the image related columns would be removed from database. Then delete the first migration file and run rake db: migrate Which would run the second migration file and create the image related columns for you in the pins table.
I can't post comment (as I must have 50 rep). All you you need to do is delete that number from your schema_migrations table in the database.
#baloo, #user3317140 - Thanks for the help. I managed to solve this after many trial and error and hope this will help others facing same problem.
To delete the Migration ID: 20140215161350 Migration name: ********** NO FILE **********, I went to create 20140215161350_create_nothing.rb with the code class CreateNothing < ActiveRecord::Migration def change end end.
This allows migration name to be found and I thereafter ran rake:db:rollback.
I did another rake:db:rollback for the $ rails generate paperclip pin image.
All clean now. Back to the ImageMagick problem.
A few days ago I created a migration for rails to add Paperclip avatars, but ended up going a different direction. Being new to Rails, I didn't know how bad of an idea it was to delete the migration file like I did.
My app works fine locally, but when run heroku run rake db:migrate I get this:
undefined method `attachment' for #<ActiveRecord::ConnectionAdapters::Table:0x000000046092e0>
It is because it is trying to run a migration called AddAttachmentAvatarToVenues, which is the migration I stupidly deleted.
It was also adding columns for the avatars that were specified in the deleted migration to the schema.rb, but I created a new migration to get rid of these. The new migration got rid of them but didn't change the heroku migration error.
Any idea how to fix this? I've done lots of googling and looking around SO and while there a lot of people with similar errors they are mostly problems with the commands that they're using.
Here is the output after the deleted migration attempted in my heroku migration.
== AddAttachmentAvatarToVenues: migrating ====================================
-- change_table(:venues)
rake aborted!
An error has occurred, this and all later migrations canceled:
undefined method `attachment' for #<ActiveRecord::ConnectionAdapters::Table:0x00000003bdb7c8>
/app/db/migrate/20130206222434_add_attachment_avatar_to_venues.rb:4:in `block in up'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/schema_statements.rb:243:in `change_table'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:466:in `block in method_missing'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:438:in `block in say_with_time'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:438:in `say_with_time'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:458:in `method_missing'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:334:in `method_missing'
/app/db/migrate/20130206222434_add_attachment_avatar_to_venues.rb:3:in `up'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:370:in `up'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:410:in `block (2 levels) in migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:410:in `block in migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:in `with_connection'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:389:in `migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:528:in `migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:720:in `block (2 levels) in migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:775:in `call'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:775:in `block in ddl_transaction'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/transactions.rb:208:in `transaction'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:775:in `ddl_transaction'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:719:in `block in migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:700:in `each'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:700:in `migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:570:in `up'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:551:in `migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/railties/databases.rake:179:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
I do see what's wrong with the output, I'm just not sure how to fix it without messing it up more.
EDIT: Here's some screenshots of file structure:
(The two similarly named ones are because there was a column I forgot to remove, but this was after I was having this problem and didn't affect it either way)
EDIT2:
Here's the deleted migration from my git history. I had added some more channels after this. They were just a couple of strings, but if that could make a difference I'll find a newer version.
class AddAttachmentAvatarToVenues < ActiveRecord::Migration
def self.up
change_table :venues do |t|
t.attachment :avatar
end
end
def self.down
drop_attached_file :venues, :avatar
end
end
Thanks in advance!
Perhaps you should look into this: How to empty DB in heroku
All your normal commands are also available in heroku, the only difference is that you have to put heroku run in front of it.
If your application hasn't gone live yet you could simply reset the database:
heroku pg:reset SHARED_DATABASE --confirm NAME_OF_THE_APP
And recreate it, using:
heroku run rake db:migrate
To seed the database:
heroku run rake db:seed
And lastly, to restart Heroku:
heroku restart
P.S. If these steps don't help, you could try running "heroku run rake db:setup" after dropping the database
I have a very annoying problem with my migrations.
First the Errormessage:
bundle exec rake db:migrate --trace
(in /home/myhomefolder/msdnaa)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
An error has occurred, all later migrations canceled:
uninitialized constant Computers
Now i have the assumption that an Update made by one of our admins is the reason why this happens every time. Even if there are no migrations at all!
What i've done (besides searching on Stack Overflow for a solution) is to grep every single file for "Computers".
Of course there are some Files containing this word and i checked them for Syntax Errors and the usual Stuff like missing ":".
Then i asked a workmate for some help (he is much more skilled with ruby than i am) and he hasn't a clue, everything looks right.
I'm using a slightly old Version of Ruby (1.8.7) and Rails (3.0.9), but i have no rights to do an update on our Server, so i have to deal with it.
And yes i asked the admin to do an update to 1.9.x and 3.1.x, but that can't be the fault 'cause it worked fine last week.
So it's one of those Errors where it SHOULD work, but it doesn't and i bet the solution is easy as drinking water, but i don't see it!
Any suggestions?
EDIT: Here ist the --trace:
/var/lib/gems/1.8/gems/activesupport-3.0.9/lib/active_support/inflector/meth ods.rb:113:in `constantize'
/var/lib/gems/1.8/gems/activesupport-3.0.9/lib/active_support/inflector/meth ods.rb:112:in `each'
/var/lib/gems/1.8/gems/activesupport-3.0.9/lib/active_support/inflector/meth ods.rb:112:in `constantize'
/var/lib/gems/1.8/gems/activesupport-3.0.9/lib/active_support/core_ext/strin g/inflections.rb:43:in `constantize'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:407 :in `load_migration'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:402 :in `migration'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:397 :in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:539 :in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:615 :in `call'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:615 :in `ddl_transaction'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:538 :in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:525 :in `each'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:525 :in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:435 :in `up'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:417 :in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/railties/databas es.rake:142
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:205:in `execute'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:158:in `invoke_with_call_ chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_ chain'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_tas k'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_e xception_handling'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:62:in `run'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_e xception_handling'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/var/lib/gems/1.8/gems/rake-0.9.2/bin/rake:32
/var/lib/gems/1.8/bin/rake:19:in `load'
/var/lib/gems/1.8/bin/rake:19
Tasks: TOP => db:migrate
My guess is that you have just added a migration called something like 20120221123456_computers.rb, and within it, you have something like...
class SomeNameThatsNotComputers < ActiveRecord::Migration
...
When Rails executes a migration, it expects to execute the file, which defines the class, and then instantiate the class, and call #up or #down on that class instance. How does Rails know what class to instantiate? It's supposed to correspond with the part of the file name following the numeric prefix and underscore, so for a file name like 20120221123456_computers.rb, the class name must be Computers.
As you said grep tells existence of "Computers" that's the problem. It means Computers is not defined but getting used. migration loads the app environment first and that time it fails bcoz Computers is not initialized