我正在尝试将我的sqlite3数据库迁移到Postgresql(我正在关注Railscasts#342,但我正在使用ubuntu)。
在我的rake db:create:all
数据库上aperitime_development
之后,我启动了带有Taps的Sinatra服务器(推送mi sqlite3 db),但是当我尝试做的时候
taps pull postgres://willy:piero@localhost/aperitime_development http://willy:ciao@localhost:5000'
数据不会复制到postgres db上,并且控制台无法正常终止:
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'
和错误继续。
任何想法?
那是我的database.yml
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
这是我的schema.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
答案 0 :(得分:1)
当您声明时,这是您迁移中的神奇咒语 柱:
create_table :example do |t|
t.integer :field, :limit => 8
end
在
:limit =>在这种情况下,8是魔术,因为postgres只签名 当你说整数时,4字节整数。这使用8字节签名 整数。
保罗鲁贝尔
答案 1 :(得分:1)
Tel列设置为整数,一些数据溢出postgresql的整数类型通常我看到电话号码存储为数据库中的字符串。因为在某些时候你可能需要一个不能作为int工作的扩展或类似的东西。
要在posgresql中将现有表从整数更改为字符,请使用以下内容创建迁移。
def up
execute <<-SQL
ALTER TABLE locals ALTER COLUMN Tel type character varying(255)
SQL
end
这应该将列类型更改为rails默认字符串表示形式。它还应该转换现有的整数。但一定要测试。