change_column
![Very extensive documentation Importance_5](https://d2vfyqvduarcvs.cloudfront.net/images/importance_5.png?1349367920)
change_column(table_name, column_name, type, options = {})
public
Changes the column’s definition according to the new options. See TableDefinition#column for details of the options you can use.
change_column(:suppliers, :name, :string, limit: 80) change_column(:accounts, :description, :text)
![Default_avatar_30](https://www.gravatar.com/avatar/2b730ab6923e7f7c669f9798445bde9f?default=http://apidock.com/images/default_avatar_30.png&size=30)
to set NULL => NO
use :null => false
change_column :my_table, :my_column, :integer, :default => 0, :null => false
![Default_avatar_30](https://www.gravatar.com/avatar/9fe836ab4b0bd00d4ec6c9daef855d3e?default=http://apidock.com/images/default_avatar_30.png&size=30)
null to no effects
change_column will not query to replace the null values when you change null to false, even if you have a default set. This may cause the query to fail (may depend on the database used).
change_column_null will optionally take a value to replace nulls if you are setting null to false. If you want to set a default and disallow nulls you likely can’t do both in one change_column call.
![Default_avatar_30](https://www.gravatar.com/avatar/2b730ab6923e7f7c669f9798445bde9f?default=http://apidock.com/images/default_avatar_30.png&size=30)
Changing to MySql:BIGINT
I can change a column type from INT to BIGINT with this command:
change_column :my_table, :my_column, :bigint
![Default_avatar_30](https://www.gravatar.com/avatar/eb24172664eda6fe8a2f39c91709b258?default=http://apidock.com/images/default_avatar_30.png&size=30)
![Default_avatar_30](https://www.gravatar.com/avatar/71f0e970c2b463a6dff67aa0586c974f?default=http://apidock.com/images/default_avatar_30.png&size=30)
Destroying Data
As far as I can tell, at least on a migration of a column from an integer to a decimal, this does not get rid of existing data.
![Default_avatar_30](https://www.gravatar.com/avatar/7e522d076dec062cf4803b87b241b82a?default=http://apidock.com/images/default_avatar_30.png&size=30)
Will this method get rid of existing data?
Will this method get rid of existing data?
![Default_avatar_30](https://www.gravatar.com/avatar/bbbc7c2470ee942c9fd13abebb709b4f?default=http://apidock.com/images/default_avatar_30.png&size=30)
On destroying data
Reply to tvle83 and pgmcgee: the destructiveness of this method depends on your database. Some databases are better at converting between disparate types than others. For example, when changing a column from a numeric type to a string type, some databases drop the data where others will turn the numbers into their string representations.
Essentially, YMMV.