简体   繁体   English

Ruby on Rails将本地csv数据加载到heroku

[英]Ruby on rails load local csv data to heroku

I am trying to import data to a postgres database in heroku. 我正在尝试将数据导入heroku中的postgres数据库。 I am able to upload the correct schema to heroku by using the command: 我可以使用以下命令将正确的架构上传到heroku:

heroku pg:psql -a [app name] < db/structure.sql

so now when I run heroku pg:psql and connect to my database I can run: 所以现在当我运行heroku pg:psql并连接到数据库时,我可以运行:

\dt

and it lists all of the tables that I want. 它列出了我想要的所有表。 However, only the schema is uploaded, not the actual data. 但是,仅上载架构,而不上载实际数据。 I have looked over a bunch of different ways to upload databases to heroku, but have been unable to get any to work. 我研究了多种将数据库上传到heroku的方法,但是一直无法正常工作。 I was wondering if there is an easy way to import local csv data to heroku. 我想知道是否有一种简单的方法将本地csv数据导入到heroku。 Locally, I can run: 在本地,我可以运行:

sqlite3 development.sqlite3
.mode csv
.import [table name] [filename]

And it imports the data that I want. 并导入我想要的数据。 Is there a similar way to do this for heroku databases? 是否有类似的方法用于heroku数据库? I know that heroku uses postgres and not sqlite3, but since I was able to load the schema easily, I thought there might be an easy way to upload data. 我知道heroku使用的是postgres而不是sqlite3,但是由于我能够轻松加载架构,因此我认为可能有一种上传数据的简便方法。 This is my first ruby on rails project I've ever attempted to publish, so any guidance would be appreciated! 这是我尝试发布的第一个ruby on rails项目,因此任何指导将不胜感激! Thanks! 谢谢!

Upload your csv to heroku and run 将您的csv上传到heroku并运行

COPY zip_codes FROM '/path/to/your_file.csv' DELIMITER ',' CSV;

in pg shell 在pg shell中

Look https://gist.github.com/jboesch/5605747 , Importing csv to heroku postgres how you can do it https://gist.github.com/jboesch/5605747将csv导入heroku postgres如何实现

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Ruby on rails 应用程序适用于本地主机,但不适用于 heroku - Ruby on rails app works on local host but, not on heroku 如何使用加载数据本地infile从迁移中将csv文件加载到rails中? - how do i load a csv file in rails from a migrate using load data local infile? 向heroku应用程序添加敏感数据(ruby on rails) - Adding sensitive data to heroku application (ruby on rails) Ruby(on Rails + Heroku)框架,用于与自定义数据进行交互 - Ruby (on Rails + Heroku) framework for interaction with custom data 如何将Ruby on Rails应用程序的本地PostgreSQL数据库部署到heroku? - How to deploy a local postgresql database of Ruby on rails app to heroku? 如何将本地数据库传输到heroku应用| Ruby on Rails - How to transfer local db to heroku app | Ruby on Rails Ruby on Rails应用程序:从Heroku到本地服务器:主要步骤是什么? - Ruby on Rails app : from Heroku to a local server : what are the main steps? LoadError:无法加载此类文件-Heroku Ruby on Rails上的travis - LoadError: cannot load such file — travis on Heroku Ruby on Rails 使用 heroku / ruby​​ on rails 无法在生产中加载字体 - Font doesn't load in production with heroku / ruby on rails Ruby on Rails - 从 CSV 文件导入数据 - Ruby on Rails - Import Data from a CSV file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM