2012-07-02 193 views
1

繼後:How to migrate from SQLite to PostgreSQL (Rails)從sqlite3遷移到Rails 3上的postgresql?

我跑在我的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

這對於PostgreSQL來說不是有效的SQL - 你可能想要一個SERIAL而不是INTEGER AUTOINCREMENT。你也許想把這個序列的manually set the nextval也設爲max(id)+1。

然後你會想要處理大多數無類型的sqlite和嚴格的PostgreSQL之間的所有其他區別。

然後,您將希望停止在開發設置和部署中使用不同的系統。這只是讓你自己感到痛苦。

0

我建議你使用gem "yaml_db",它的目的是將表從一個數據庫移動到另一個。 https://github.com/ludicast/yaml_db#readme

你可以簡單地通過這個寶石完成所有的事情與一個很好的文檔。它有兩個基本的命令,所以沒什麼困難的。