This project is archived and is in readonly mode.

#1434 ✓stale

add_column with non-existing type

Reported by qoobaa | November 22nd, 2008 @ 04:07 PM | in 2.x

We can add column with non-existing (or misspelled) type.

add_column :users, :enabled, :bool # misspelled - should be :boolean

Migration works fine with SQLite3, but it can't be undone:

rake db:migrate:down VERSION=20081122152613 --trace

You have a nil object when you didn't expect it!
The error occurred while evaluating nil.to_sym
/home/kuba/edetailing/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb:423:in `column'
/home/kuba/edetailing/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:318:in `copy_table'
/home/kuba/edetailing/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:312:in `each'
/home/kuba/edetailing/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:312:in `copy_table'
/home/kuba/edetailing/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb:98:in `create_table'
/home/kuba/edetailing/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:310:in `copy_table'
/home/kuba/edetailing/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:304:in `move_table'
/home/kuba/edetailing/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:297:in `alter_table'
/home/kuba/edetailing/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in `transaction'
/home/kuba/edetailing/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:296:in `alter_table'
/home/kuba/edetailing/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:228:in `remove_column'
/home/kuba/edetailing/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:227:in `each'
/home/kuba/edetailing/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:227:in `remove_column'
/home/kuba/edetailing/vendor/rails/activerecord/lib/active_record/migration.rb:346:in `send'
/home/kuba/edetailing/vendor/rails/activerecord/lib/active_record/migration.rb:346:in `method_missing'
/home/kuba/edetailing/vendor/rails/activerecord/lib/active_record/migration.rb:326:in `say_with_time'

Comments and changes to this ticket

  • qoobaa

    qoobaa November 22nd, 2008 @ 05:28 PM

    • Tag changed from activerecord, edge, migrations, sqlite to activerecord, edge, migrations, patch, sqlite

    The patch solves problem with reversing migrations. We should also consider restricting SQLite3 types to avoid mistakes like above.

  • Pratik

    Pratik March 6th, 2009 @ 07:46 PM

    • Assigned user set to “Pratik”

    Shouldn't the real fix be to raise an exception when someone tries to add a column of unknown type ?

    Also, the patch is missing tests.


  • qoobaa

    qoobaa March 6th, 2009 @ 10:54 PM

    AFAIR (it was few months ago) the problem is that SQLite3 doesn't have any strict set of types. Restricting them is the easiest way to fix the problem but it might cause problems when somebody uses strange type names already (don't know what for :-) ).

  • qoobaa

    qoobaa March 6th, 2009 @ 11:00 PM

    It's also really nasty bug. When you create such strange typed column, there's no easy way to remove it - SQLite3 doesn't support removing columns from tables. My solution was the easiest way to repair my DB.

  • Pratik

    Pratik May 18th, 2009 @ 10:08 PM

    • State changed from “new” to “stale”
  • bterkuile

    bterkuile July 29th, 2009 @ 03:53 PM

    I had the same problem, setting a type to :bool for sqlite3 will cause many problems. At least it should be converted to :boolean when a sqlite database is used. The problem is described at: so I won't add much words to that, except how I resolved the problem.

    Since migrations fail when the field has type bool it has to be changed manually. Since I don't like the code to change the column type for sqlite my most elegant solution was in the console:
    ActiveRecord::Base.connection.change_column :table_name, :column_name, :boolean, :default => false

Create your profile

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

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket

Referenced by