rake db:create:all
을 시도 그리고 네, 그것은 레일 응용 프로그램에서 여러 DB 연결이 가능합니다.
이것은 내가 한 번했기 때문에 ActiveRecord::Base
에서 상속받은 두 개의 클래스를 만들고이 클래스 내부의 연결을 설정합니다.
그럼 내가 대신 아래 직접 ActiveRecord
의 이러한 클래스 중 하나에 내 모든 모델을 상속 한 예입니다
: 그럼 모두 TEST1 및 TEST2 데이터베이스에 대한 두 가지 모델이
database.yml file
#app uses two database
#1 - test1
#2 - test2
test1:
adapter: mysql
encoding: utf8
database: test1
username: root
password: xxx
host: localhost
test2:
adapter: mysql
encoding: utf8
database: test2
username: root
password: xxx
host: localhost
class Test1Base < ActiveRecord::Base
self.abstract_class = true
establish_connection("test1")
end
class Test2Base < ActiveRecord::Base
# No corresponding table in the DB.
self.abstract_class = true
establish_connection("test2")
end
다음 데이터베이스에 따라 모델을 상속받습니다.
class School < Test1Base
#code
end
class Student < Test2Base
#code
end
안녕 사 미라, 당신의 대답은 올바른 것입니다. 나는 "portal_development"에 대한 모델을 마이그레이션 할 수있는 또 하나의 질문이 있습니다. 도와주세요 ... –
안녕하세요 @Shamith, 오ops, 그 오타되었습니다, 그 env 이름이 있어야합니다, 위의 database.yml을 편집했습니다, 예를 들어 내 기존 파일을 삭제하는 것을 잊어 버렸습니다. 죄송합니다 ... : D – sameera207