在Rails 3上从sqlite3迁移到postgresql?

时间:2012-07-02 09:19:14

标签: database ruby-on-rails-3 sqlite postgresql

发布帖子:How to migrate from SQLite to PostgreSQL (Rails)

我在我的Rails应用中运行sqlite3 development.sqlite3 .dump | psql mypgdb mypguser并且我收到此错误(对于我的应用中的所有模型/表格都相同):

ERROR:  current transaction is aborted, commands ignored until end of transaction block
ERROR:  current transaction is aborted, commands ignored until end of transaction block
ERROR:  current transaction is aborted, commands ignored until end of transaction block
ERROR:  current transaction is aborted, commands ignored until end of transaction block
ERROR:  current transaction is aborted, commands ignored until end of transaction block
ERROR:  current transaction is aborted, commands ignored until end of transaction block
ERROR:  current transaction is aborted, commands ignored until end of transaction block
ERROR:  current transaction is aborted, commands ignored until end of transaction block
ERROR:  current transaction is aborted, commands ignored until end of transaction block
ERROR:  current transaction is aborted, commands ignored until end of transaction block
ERROR:  current transaction is aborted, commands ignored until end of transaction block
ERROR:  syntax error at or near "AUTOINCREMENT"
LINE 1: ...E TABLE "projects" ("id" INTEGER PRIMARY KEY AUTOINCREM...

会欣赏一些建议/修复。谢谢!

2 个答案:

答案 0 :(得分:2)

这对于PostgreSQL来说不是有效的SQL - 您可能需要SERIAL而不是INTEGER AUTOINCREMENT。您可能希望这些序列的manually set the nextval也达到max(id)+1。

然后你会想要处理一个无类型的sqlite和一个严格的PostgreSQL之间的所有其他差异。

然后,您将要在开发设置和部署中停止使用不同的系统。这只是让自己痛苦。

答案 1 :(得分:0)

我建议您使用gem "yaml_db",其目的是将表从一个数据库移动到另一个数据库。 https://github.com/ludicast/yaml_db#readme

你可以通过这个宝石简单地完成所有工作。它有2个基本命令,所以没什么难的。