在 ROR 中将整数更改为 bigint
change an integer to bigint in ROR
我需要将我的 table 整数更改为 BIGINT
我正在使用 RoR
和 SQLLite
。
如何通过命令行将现有的 table 字段从 Int
修改为 BigInt
?
您可以通过迁移来做到这一点。这是文档的 link:http://edgeguides.rubyonrails.org/active_record_migrations.html
基本上,你需要运行:
rails g migration change_your_column_to_bigint
并将此代码添加到迁移新迁移文件中:
def up
execute <<-SQL
ALTER TABLE ip_to_countries
ALTER COLUMN your_column TYPE bigint USING your_column::bigint
SQL
end
为了记录,我从这里偷了这个:How do I change a string column into a bigint?,但没有将其标记为重复,因为它涉及转换字符串列。
现在我收到这个错误
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 TABL
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)
在运行之后
class ChangeMileageToBigint < ActiveRecord::Migration
def change
execute <<-SQL
ALTER TABLE posts
ALTER COLUMN mileage TYPE bigint USING mileage::bigint
SQL
end
end
我需要将我的 table 整数更改为 BIGINT
我正在使用 RoR
和 SQLLite
。
如何通过命令行将现有的 table 字段从 Int
修改为 BigInt
?
您可以通过迁移来做到这一点。这是文档的 link:http://edgeguides.rubyonrails.org/active_record_migrations.html
基本上,你需要运行:
rails g migration change_your_column_to_bigint
并将此代码添加到迁移新迁移文件中:
def up
execute <<-SQL
ALTER TABLE ip_to_countries
ALTER COLUMN your_column TYPE bigint USING your_column::bigint
SQL
end
为了记录,我从这里偷了这个:How do I change a string column into a bigint?,但没有将其标记为重复,因为它涉及转换字符串列。
现在我收到这个错误
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 TABL
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)
在运行之后
class ChangeMileageToBigint < ActiveRecord::Migration
def change
execute <<-SQL
ALTER TABLE posts
ALTER COLUMN mileage TYPE bigint USING mileage::bigint
SQL
end
end