我正在尝试将我的sqlite3 db迁移到Postgresql(我正在跟踪Railscasts#342,但我在ubuntu上)。
在数据库上执行rake db:create:all
之后,我启动了一个带有Taps的Sinatra服务器(以推送mi sqlite3 db),但是当我尝试这样做时
taps pull postgres://willy:piero@localhost/aperitime_development http://willy:ciao@localhost:5000'
postgres数据库上未复制数据,控制台未正确终止:
Receiving schema
Schema: 0% | | ETA: --:--:--
Schema: 25% |========== | ETA: 00:00:07
Schema: 50% |===================== | ETA: 00:00:03
Schema: 75% |=============================== | ETA: 00:00:01
Schema: 100% |==========================================| Time: 00:00:04
Receiving data
4 tables, 800 records
/usr/lib/ruby/gems/1.9.1/gems/sequel-3.20.0/lib/sequel/adapters/postgres.rb:175:in 'async_exec': PG::Error: ERROR: integer out of range (Sequel::DatabaseError)
from /usr/lib/ruby/gems/1.9.1/gems/sequel-3.20.0/lib/sequel/adapters/postgres.rb:175:in `block (2 levels) in execute'
from /usr/lib/ruby/gems/1.9.1/gems/sequel-3.20.0/lib/sequel/database/logging.rb:28:in `log_yield'
from /usr/lib/ruby/gems/1.9.1/gems/sequel-3.20.0/lib/sequel/adapters/postgres.rb:175:in `block in execute'
from /usr/lib/ruby/gems/1.9.1/gems/sequel-3.20.0/lib/sequel/adapters/postgres.rb:158:in `check_disconnect_errors'
from /usr/lib/ruby/gems/1.9.1/gems/sequel-3.20.0/lib/sequel/adapters/postgres.rb:175:in `execute'
错误还在继续。
有什么想法吗?
那是我的数据库
development:
adapter: postgresql
encoding: unicode
database: aperitime_development
pool: 5
username: willy
password: piero
test:
adapter: postgresql
encoding: unicode
database: aperitime_test
pool: 5
username: willy
password: piero
这是我的模式.rb
ActiveRecord::Schema.define(:version => 20120630154954) do
create_table "locals", :force => true do |t|
t.string "nome"
t.string "indirizzo"
t.text "descrizione"
t.integer "Tel", :limit => 8
t.integer "voto"
t.string "mappa"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "users", :force => true do |t|
t.string "nome"
t.string "email"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "password_digest"
t.string "remember_token"
t.boolean "admin", :default => false
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["remember_token"], :name => "index_users_on_remember_token"
end
最佳答案
Tel列被设置为integer,您的一些数据溢出了postgresql的integer类型通常我看到电话号码被存储为数据库中的字符串。因为在某个时候,你可能需要一个扩展或者类似的东西,它不能作为int工作。
若要将现有表从整数更改为POSGRESQL中的字符,请用以下方法创建迁移。
def up
execute <<-SQL
ALTER TABLE locals ALTER COLUMN Tel type character varying(255)
SQL
end
这会将列类型更改为rails默认字符串表示形式。它还应该转换现有的整数。但一定要测试。
关于ruby-on-rails - Sqlite3通过Taps上的Taps错误迁移到Postgresql,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11581024/