Wenn dort auch Wörter vorhanden sind wird die Migration nicht funktionieren.
Welche DB benutzt du? Versuch mal mit den gängigen Tools die Spalte in int umzubiegen.
Wird da auch nicht funktionieren vermute ich mal weil die DB wohl kein "Ich bin ein String"
in einen int konverteiren kann.

Michael Kastner schrieb:
Hallo,

ich steige hier überhaupt nicht mehr durch. Ich möchte per migration eine string-Spalte in eine int-Spalte konvertieren.

In der Spalte sind schon Werte eingetragen. Zum Teil auch Wörter. Aber das müßte die migration schlucken.

Meine Migration sieht so aus:

class ChangeUsersIdentityKeyToInt < ActiveRecord::Migration
  def self.up
    change_column :users, :identity_key, :int
  end
  def self.down
    change_column :users, :identity_key, :string
  end
end



Wenn ich die migration mit aufrufe, erhalte ich eine Fehlermeldung. Mit --trace dieses:

** Execute db:migrate
== ChangeUsersIdentityKeyToInt: migrating =====================================
-- change_column(:users, :identity_key, :int)
rake aborted!
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:272:in `type_to_sql'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:371:in `change_column'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:275:in `send'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:275:in `method_missing'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:259:in `say_with_time'
/usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:259:in `say_with_time'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:273:in `method_missing'
./db/migrate//009_change_users_identity_key_to_int.rb:3:in `real_up'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:212:in `send'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:212:in `migrate'
/usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:212:in `migrate'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:335:in `migrate'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:330:in `each'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:330:in `migrate'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:297:in `up'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:288:in `migrate'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/tasks/databases.rake:4
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `call'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `each'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in `invoke'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `synchronize'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `invoke'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in `top_level'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in `each'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in `top_level'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in `standard_exception_handling'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1733:in `top_level'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1711:in `run'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in `standard_exception_handling'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1708:in `run'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/bin/rake:7
/usr/local/bin/rake:16:in `load'
/usr/local/bin/rake:16

Schlau werde ich daraus nicht.

Viele Grüße

Michael Kastner


_______________________________________________ rubyonrails-ug mailing list [email protected] http://mailman.headflash.com/mailman/listinfo/rubyonrails-ug


_______________________________________________
rubyonrails-ug mailing list
[email protected]
http://mailman.headflash.com/mailman/listinfo/rubyonrails-ug

Antwort per Email an