Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 Rails和Postgresql迁移更改列类型_Ruby On Rails 4_Postgresql 9.4 - Fatal编程技术网

Ruby on rails 4 Rails和Postgresql迁移更改列类型

Ruby on rails 4 Rails和Postgresql迁移更改列类型,ruby-on-rails-4,postgresql-9.4,Ruby On Rails 4,Postgresql 9.4,我需要在rails中不时更改列类型。我无法更改列类型。它显示此错误 "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: Sp

我需要在rails中不时更改列类型。我无法更改列类型。它显示此错误

"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'"
下面是我尝试过的格式

change_column(:table_name, :column_name, :datetime )
并尝试了以下格式

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

psql版本-9.4.4&任何人都可以给我解决方案。

请将错误消息的格式设置为:(1)它们不是粗体的,(2)是代码块,类似于您的后可能副本末尾的两行。Net是指您应该删除现有列并添加datetime列,因为没有合理的方法从times生成datetime。我不会删除该列。如果我删除了该列并删除了其值,请将错误消息的格式设置为:(1)它们不是粗体的,(2)是代码块,类似于您的后可能副本末尾的两行。Net是指您应该删除现有列并添加datetime列,因为没有合理的方法从times生成datetimes。如果我删除了该列并删除了其值,我不会删除该列。