【问题标题】:Migrating from sqlite3 to postgresql on Rails 3?在 Rails 3 上从 sqlite3 迁移到 postgresql?
【发布时间】:2012-07-02 16:52:32
【问题描述】:

关注帖子: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...

不胜感激一些建议/修复。谢谢!

【问题讨论】:

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


    【解决方案1】:

    对于 PostgreSQL,这不是有效的 SQL - 您可能需要 SERIAL 而不是 INTEGER AUTOINCREMENT。您可能也想将这些序列的manually set the nextval 设置为 max(id)+1。

    然后您将需要处理大多数无类型的 sqlite 和严格的 PostgreSQL 之间的所有其他差异。

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

    【讨论】:

      【解决方案2】:

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

      你可以通过这个 gem 和一个很好的文档来完成所有的事情。它有 2 个基本命令,所以没什么难的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-02-14
        • 1970-01-01
        • 2016-04-13
        • 1970-01-01
        • 2013-09-18
        • 2022-12-03
        • 1970-01-01
        相关资源
        最近更新 更多