1

sqlite3 db を Postgresql に移行しようとしています (Railscasts #342 に従っていますが、ubuntu を使用しています)。rake db:create:all私のデータベースの後、aperitime_developmentタップで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
4

2 に答える 2

1

Tel 列が整数として設定されているため、データの一部が postgresql の整数型をオーバーフローしています 通常、電話番号がデータベースに文字列として格納されていることがわかります。ある時点で、int として機能しない拡張などが必要になる可能性があるためです。

posgresql で既存のテーブルを整数から文字に変更するには、次のように移行を作成します。

def up 
    execute <<-SQL
        ALTER TABLE locals ALTER COLUMN Tel type character varying(255)
    SQL
end

これにより、列のタイプがレールのデフォルトの文字列表現に変更されます。また、既存の整数を変換する必要があります。しかし、必ずテストしてください。

于 2012-07-20T15:32:30.337 に答える