如何将我的Rails应用程序从Sqlite3切换到postgresql ?

时间:2022-01-10 05:33:54

So I started working on a Rails app recently and we decided (well not me, the person working on it with me) that we should switch from Sqlite3 to Postgresql. I've installed Postgresql on our server properly, created the databases for dev, prod, and test, and updated my Gemfile and database.yml files with the code for Postgres. The thing I'm unsure of now, is how to switch out all the files in the db directory with the Postgres databases. Do I just delete the contents of the db directory in my app and run rake db:create?

所以我最近开始开发Rails应用程序,我们决定(当然不是我,和我一起开发的那个人)我们应该从Sqlite3切换到Postgresql。我已经在服务器上正确地安装了Postgresql,为dev、prod和test创建了数据库,并更新了Gemfile和数据库。yml文件,带有Postgres的代码。现在我不确定的是,如何用Postgres数据库切换db目录中的所有文件。我是否只是在app中删除了db目录的内容,然后运行rake db:create?

1 个解决方案

#1


4  

You'll want to edit config/database.yml to use postgresql instead of sqlite.

您需要编辑配置/数据库。yml使用postgresql代替sqlite。

The migrations in db/migrate/*.rb are hopefully cross-database compatible, and wont need to be changed.

在db / migrate / *迁移。rb是跨数据库兼容的,不需要修改。

Running rake db:create db:migrate with the new database.yml should create the PostgreSQL database and you'll be up and running.

运行rake db:创建db:迁移新数据库。yml应该创建PostgreSQL数据库,您将启动并运行它。

In reality, you'll probably run into various problems, but this will be a starting point.

实际上,您可能会遇到各种各样的问题,但这将是一个起点。

#1


4  

You'll want to edit config/database.yml to use postgresql instead of sqlite.

您需要编辑配置/数据库。yml使用postgresql代替sqlite。

The migrations in db/migrate/*.rb are hopefully cross-database compatible, and wont need to be changed.

在db / migrate / *迁移。rb是跨数据库兼容的,不需要修改。

Running rake db:create db:migrate with the new database.yml should create the PostgreSQL database and you'll be up and running.

运行rake db:创建db:迁移新数据库。yml应该创建PostgreSQL数据库,您将启动并运行它。

In reality, you'll probably run into various problems, but this will be a starting point.

实际上,您可能会遇到各种各样的问题,但这将是一个起点。