Ruby on rails 如何将sqlite3表转换为postgresql表?
我在不知道Heroku需要Postgresql的情况下启动了一个Rails项目。现在,我想将sqlite3表转换为postgresql表。我怎么做 我找到了一种获取SQL插入的方法:Ruby on rails 如何将sqlite3表转换为postgresql表?,ruby-on-rails,postgresql,Ruby On Rails,Postgresql,我在不知道Heroku需要Postgresql的情况下启动了一个Rails项目。现在,我想将sqlite3表转换为postgresql表。我怎么做 我找到了一种获取SQL插入的方法: BEGIN TRANSACTION; insert into places ("id", "name", "content", "tags", "created_at", "updated_at") values ('0', 'bac à papier', NULL, 'bac de recyclage', '13
BEGIN TRANSACTION;
insert into places ("id", "name", "content", "tags", "created_at", "updated_at") values ('0', 'bac à papier', NULL, 'bac de recyclage', '13309980782012-03-06 03:57:21.219233', '13309980782012-03-06 03:57:21.219233');
insert into places ("id", "name", "content", "tags", "created_at", "updated_at") values ('1', 'bac PVM', 'plastique/verre/métal', NULL, '13310076572012-03-06 03:57:21.219233', '13310076572012-03-06 03:57:21.219233');
insert into places ("id", "name", "content", "tags", "created_at", "updated_at") values ('2', 'bac de déchets', NULL, 'poubelle', '13310076572012-03-06 03:57:21.219233', '13310076572012-03-06 03:57:21.219233');
insert into places ("id", "name", "content", "tags", "created_at", "updated_at") values ('3', 'cafétéria', '', '', '2012-03-06 03:57:21.219233', '2012-03-06 03:57:21.219233');
insert into places ("id", "name", "content", "tags", "created_at", "updated_at") values ('4', 'compost', NULL, NULL, '2012-03-06 03:57:21.219233', '2012-03-06 03:57:21.219233');
insert into places ("id", "name", "content", "tags", "created_at", "updated_at") values ('5', 'consigne', NULL, NULL, '2012-03-06 03:57:21.219233', '2012-03-06 03:57:21.219233');
insert into places ("id", "name", "content", "tags", "created_at", "updated_at") values ('6', 'CRD', NULL, NULL, '2012-03-06 03:57:21.219233', '2012-03-06 03:57:21.219233');
insert into places ("id", "name", "content", "tags", "created_at", "updated_at") values ('7', 'ressources matérielles', NULL, NULL, '2012-03-06 03:57:21.219233', '2012-03-06 03:57:21.219233');
insert into places ("id", "name", "content", "tags", "created_at", "updated_at") values ('8', 'sécurité', NULL, NULL, '2012-03-06 03:57:21.219233', '2012-03-06 03:57:21.219233');
insert into places ("id", "name", "content", "tags", "created_at", "updated_at") values ('10', 'technicien chimie', NULL, NULL, '2012-03-06 03:57:21.219233', '2012-03-06 03:57:21.219233');
insert into places ("id", "name", "content", "tags", "created_at", "updated_at") values ('11', 'technicien biologie', NULL, NULL, '2012-03-06 03:57:21.219233', '2012-03-06 03:57:21.219233');
insert into places ("id", "name", "content", "tags", "created_at", "updated_at") values ('12', 'service informatique', NULL, NULL, '2012-03-06 03:57:21.219233', '2012-03-06 03:57:21.219233');
insert into places ("id", "name", "content", "tags", "created_at", "updated_at") values ('13', 'îlot multi-récupération', 'face au B-227', NULL, '2012-03-06 03:57:21.219233', '2012-03-06 03:57:21.219233');
insert into places ("id", "name", "content", "tags", "created_at", "updated_at") values ('14', 'récupérateurs extérieurs', NULL, NULL, '2012-03-06 03:57:21.219233', '2012-03-06 03:57:21.219233');
COMMIT;
解决方案
下面是我如何解决这个问题的:
我用Chris的解决方案告诉rails我想使用PostgreSQL。然后,我运行了db:migrate
为了将SQLite表转换为PostgreSQL表,我使用了一个Linux程序sliteman来管理SQLite数据库。有了这个实用程序,我能够将表转换为SQL插入。我登录到PostgreSQL并应用了插入
瞧 如果您只是想让本地数据库在postgres上运行以匹配heroku,只需将database.yml更改为如下所示:
development:
adapter: postgresql
encoding: utf8
database: development
pool: 5
username: postgres
password:
test: &TEST
adapter: postgresql
encoding: utf8
database: test
pool: 5
username: postgres
password:
production:
adapter: postgresql
encoding: utf8
database: production
pool: 5
username: postgres
password:
cucumber:
<<: *TEST
开发:
适配器:postgresql
编码:utf8
数据库:开发
游泳池:5
用户名:postgres
密码:
测试:&测试
适配器:postgresql
编码:utf8
数据库:测试
游泳池:5
用户名:postgres
密码:
制作:
适配器:postgresql
编码:utf8
数据库:生产
游泳池:5
用户名:postgres
密码:
黄瓜: