Rails and Postgresql Migration change column type

孤者浪人 提交于 2019-12-11 14:49:58

问题


I need to change the column type from time to datetime in rails.I cant't change the column type.It show this error

"rake aborted!
 StandardError: An error has occurred, this and all later migrations canceled:
PG::DatatypeMismatch: ERROR:  column "fun_from" cannot be cast automatically to type timestamp without time zone
HINT:  Specify a USING expression to perform the conversion.
 : ALTER TABLE "general_infos" ALTER COLUMN "fun_from" TYPE timestamp/home/PCA/db/migrate/20150730102811_change_data_type_in_general_infos.rb:3:in `change'
 ActiveRecord::StatementInvalid: PG::DatatypeMismatch: ERROR:  column "fun_from" cannot be cast automatically to type timestamp without time zone
 HINT:  Specify a USING expression to perform the conversion.
:     ALTER TABLE "general_infos" ALTER COLUMN "fun_from" TYPE timestamp
/home/PCA/db/migrate/20150730102811_change_data_type_in_general_infos.rb:3:in `change'
PG::DatatypeMismatch: ERROR:  column "fun_from" cannot be cast automatically to type timestamp without time zone
HINT:  Specify a USING expression to perform the conversion.
/home/PCA/db/migrate/20150730102811_change_data_type_in_general_infos.rb:3:in `change'"

Below format i tried,

change_column(:table_name, :column_name, :datetime )

and also tried below format

change_column :table_name, :column_name, 'datetime USING CAST(column_name AS datetime)'

psql version - 9.4.4 & Any one give me solution.

来源:https://stackoverflow.com/questions/31723737/rails-and-postgresql-migration-change-column-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!