0

I am trying to change my table column from an integer to a bigint I create a migration and then added this code to the migration file.

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

However, I am getting this error when running 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 Answer 1

1

According to the documentation sqlite it is not supported you will need to copy the data to new column of bigint type and change its name

Sign up to request clarification or add additional context in comments.

1 Comment

it seems that it's better to create a new table and rename it after copying over the data

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.