将DB表列从整数更改为BigInt时出错

时间:2015-03-15 21:26:10

标签: ruby-on-rails sqlite rake

我正在尝试将我的表列从整数更改为bigint 我创建了一个迁移,然后将此代码添加到迁移文件中。

class ChangeMileageToBigint < ActiveRecord::Migration
  def change
  execute <<-SQL
    ALTER TABLE posts
    ALTER COLUMN mileage TYPE bigint USING mileage::bigint
  SQL
end
end

但是,运行rake db:migrate

时出现此错误
C:\Sites\jeepjig>rake db:migrate
DL is deprecated, please use Fiddle
== 20150315145856 ChangeMileageToBigint: migrating ============================
-- execute("    ALTER TABLE posts\n    ALTER COLUMN mileage TYPE bigint USING mileage::bigint\n")
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: near "ALTER": syntax error:     ALTER TABLE posts
    ALTER COLUMN mileage TYPE bigint USING mileage::bigint
C:/Sites/jeepjig/db/migrate/20150315145856_change_mileage_to_bigint.rb:3:in `change'
C:in `migrate'
ActiveRecord::StatementInvalid: SQLite3::SQLException: near "ALTER": syntax error:     ALTER TABLE posts
    ALTER COLUMN mileage TYPE bigint USING mileage::bigint
C:/Sites/jeepjig/db/migrate/20150315145856_change_mileage_to_bigint.rb:3:in `change'
C:in `migrate'
SQLite3::SQLException: near "ALTER": syntax error
C:/Sites/jeepjig/db/migrate/20150315145856_change_mileage_to_bigint.rb:3:in `change'
C:in `migrate'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

1 个答案:

答案 0 :(得分:1)

根据文档sqlite,它不受支持 您需要将数据复制到bigint类型的新列并进行更改 它的名字