views:

209

answers:

3

I've been using sqlite3 for my database under development and my app has gotten complex enough that it's a bit slow to work with.

I've just switched to MySQL and run rake db:create ; rake db:migrate and one of my migrations failed with the following error message:

undefined method `alter_table` for #<ActiveRecord::ConnectionAdapters::MysqlAdapter:0xb6e6088c>

I've had a quick google and turned up nothing. Then I checked the API and there is no documented method alter_table. However, it does work with sqlite3!

Here's my migration:

class AddSettingsToUsers < ActiveRecord::Migration
  def self.up
    alter_table :users do |t|
      t.text signature
      ...
    end
  end

  ...

end

This works as expected with sqlite3.

Am I going crazy? Did I just invent this method and it happened to be an undocumented feature that works only on a subset of supported databases?

Does anyone have some insight on this??

+1  A: 

This shows there's an alter_table protected method in the Sqlite adapter.

JRL
Hmm. Why can I call this directly? Is this an oversight that I should submit a bug report for?
nfm
+2  A: 

It seems to be unique just to sqlite

yvaine:activerecord-2.3.5 root# find . -type f -exec grep -l alter_table {} \;

./lib/active_record/connection_adapters/sqlite_adapter.rb

It'll probably be safer just to use the change_column method instead, as that abstracts the alter table method.

Rilindo
+2  A: 

As the others mentioned, this is probably a method used only for sqlite. The documention mentions change_table, so use that one instead, it should work the same way:

class AddSettingsToUsers < ActiveRecord::Migration
  def self.up
    change_table :users do |t|
      t.text :signature
      ...
    end
  end

  ...

end
Jimmy Stenke