#519 stale
barunio

Migration error with rails 2.1 and drop_table -- still looking for schema_info

Reported by barunio | July 1st, 2008 @ 01:03 AM | in 2.x

After upgrading to Rails 2.1 I noticed that migrations are broken in this way:

I created a new migration as follows:

class TestMigration < ActiveRecord::Migration

def self.up

create_table :blah do |t|

t.integer :something

end

end

def self.down

drop_table :blah

end

end

If I run the migration all is well. If I try to roll back the migration, though, I get the following error:

Mysql::Error: Table 'myproject_development.schema_info' doesn't exist: select version from schema_info limit 1

The migration is looking for schema_info when it should be looking for schema_migrations.

Note that this error seems to be associated with drop_table in particular, since if my self.down action is "rename_table :blah, :blah2", everything works fine without an error.

Is this a known bug or am I missing something? If it is a bug, is there a patch for it?

Thanks!

Comments and changes to this ticket

  • axs89

    axs89 July 1st, 2008 @ 01:54 AM

    I'm also seeing the same problem - Rails 2.1

  • Ernie Miller

    Ernie Miller July 1st, 2008 @ 02:39 AM

    I can't duplicate this. Copied your specific migration to a file, got the following with rake db:migrate:

    C:\Users\Neo\blah>rake db:migrate

    (in C:/Users/Neo/blah)

    == 20080701012651 TestMigration: migrating ====================================

    -- create_table(:blah)

    -> 0.0030s

    == 20080701012651 TestMigration: migrated (0.0040s) ===========================

    C:\Users\Neo\blah>rake db:migrate VERSION=0

    (in C:/Users/Neo/blah)

    == 20080701012651 TestMigration: reverting ====================================

    -- drop_table(:blah)

    -> 0.0040s

    == 20080701012651 TestMigration: reverted (0.0040s) ===========================

  • barunio

    barunio July 1st, 2008 @ 02:48 AM

    hm, strange. well i just tried it again and still get that error with the exact code i've provided. are you trying this from a new rails project? (i wonder if perhaps the error only occurs when dealing with an older project that was originally created pre-2.1)

  • Ernie Miller

    Ernie Miller July 1st, 2008 @ 03:18 AM

    I did try with a new rails project. From glancing through the migration code, it looked to me like the schema_info table undergoes a one-time conversion to schema_migrations in activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, in the initialize_schema_migrations_table method, which gets called by Migrator.initialize. Right near the very top of the method, it has a condition:

    unless tables.detect { |t| t == sm_table }

    which should stop the entire method from running once that table has been created.

  • David Mitchell

    David Mitchell July 3rd, 2008 @ 01:27 AM

    I have a project that used 2.0.1 and can confirm that this error is not an isolated incident. It only happens when trying to revert migrations. I dropped the entire database, migrated and then reverted and it died while still doing the first migration back.

  • David Mitchell

    David Mitchell July 3rd, 2008 @ 01:33 AM

    Here's the stack trace for the error:

    ** Invoke db:migrate (first_time)

    ** Invoke environment (first_time)

    ** Execute environment

    ** Execute db:migrate

    == 41 CreateMilestones: reverting =============================================

    -- drop_table(:milestones)

    rake aborted!

    Mysql::Error: Table 'nms_dev.schema_info' doesn't exist: select version from schema_info limit 1

    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:147:in `log'

    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/mysql_adapter.rb:299:in `execute'

    C:/dev/globaltrack/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/mysql_adapter.rb:59:in `reverse_foreign_keys'

    C:/dev/globaltrack/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/abstract_adapter.rb:27:in `drop_table'

    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/mysql_adapter.rb:408:in `drop_table'

    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:330:in `send'

    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:330:in `method_missing'

    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:310:in `say_with_time'

    c:/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'

    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:310:in `say_with_time'

    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:326:in `method_missing'

    ./db/migrate//041_create_milestones.rb:15:in `down_without_benchmarks'

    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:264:in `send'

    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:264:in `migrate'

    c:/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'

    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:264:in `migrate'

    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:430:in `migrate'

    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:420:in `each'

    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:420:in `migrate'

    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:361:in `down'

    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:341:in `migrate'

    c:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/tasks/databases.rake:99

    c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `call'

    c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `execute'

    c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `each'

    c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `execute'

    c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:508:in `invoke_with_call_chain'

    c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `synchronize'

    c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `invoke_with_call_chain'

    c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:494:in `invoke'

    c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1931:in `invoke_task'

    c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'

    c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `each'

    c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'

    c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'

    c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1903:in `top_level'

    c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1881:in `run'

    c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'

    c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1878:in `run'

    c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/bin/rake:31

    C:/ruby/bin/rake:16:in `load'

    C:/ruby/bin/rake:16

  • David Mitchell

    David Mitchell July 3rd, 2008 @ 07:26 AM

    I took a closer look at the stack trace, updated all my plugins and it looks like my problem was related to an older version of the redhillonrails plugins. Hope that helps somebody who was in the same situation.

  • Joshua Peek

    Joshua Peek October 5th, 2008 @ 03:17 PM

    • → Tag changed from “2.1 bug migrations” to “"2.1" bug migrations”
    • → State changed from “new” to “stale”

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Source available from github

The Git repository resides at http://github.com/rails

Check out the current development trunk (Edge Rails) with:

git clone git://github.com/rails/rails.git

Creating or reviewing a patch

See the contributor guide.

Creating a feature request

Please don't. If you want a new feature in Rails, you'll have to pull up your sleeves and get busy yourself. Or convince someone else to do it. See the contributor guide on how to get going. But posting them here is just going to lead to ticket root.

Creating a bug report

When creating a bug report, be sure to include as much relevant information as possible. Post the code sample that causes the problem. Preferably, alter the unit tests and show through either changed or added tests how the expected behavior is not occuring.

Security vulnerabilities should be reported via an email to security@rubyonrails.org, do not use trac for reporting security vulnerabilities. All content in trac is publicly available as soon as it is posted.

Then don't get your hopes up. Unless you have a "Code Red, Mission Critical, The World is Coming to an End" kinda bug, you're creating this ticket in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the ticket automatically will see any activity or that others will jump to fix it. Creating a ticket like this is mostly to help yourself start on the path of fixing the problem and for others to sign on to with a "I'm having this problem too".

Shared Ticket Bins