简体   繁体   English

如何将数据从.sqlite3文件加载到Ruby on Rails应用程序

[英]How to load the data from a .sqlite3 file to a Ruby on Rails Application

I have a production.sqlite3 file which I want to import its data to the current rails project, the database schema is match between the file and my current project. 我有一个production.sqlite3文件,我想将其数据导入到当前的rails项目中,数据库模式在该文件和我的当前项目之间匹配。 I did copy the content to the development.sqlite3 file but this does not work. 我确实将内容复制到development.sqlite3文件,但这不起作用。 The only way I know to insert data to the database is by loading some yml file or use the seed command. 我知道将数据插入数据库的唯一方法是加载一些yml文件或使用seed命令。 Is there any magic command or other ways to let the rails loading the data from .sqlite file? 有什么魔术命令或其他方法可以让Rails从.sqlite文件加载数据吗? Because from what I disover, the behavior of rails is that it only creates the .sqlite3 file when you do rake db:create &migrate, but it will ignore what ever manual changes happen in that file. 因为从我的观点出发,rails的行为是,它仅在您执行db:create&migrate时创建.sqlite3文件,但是它将忽略该文件中发生的任何手动更改。 Please help! 请帮忙!

It looks like renaming your .sqlite3 file should work. 重命名您的.sqlite3文件似乎可以正常工作。 Make sure you have restarted your server, and that the server is running in the correct environment. 确保已重新启动服务器,并且该服务器在正确的环境中运行。 If you move both the .sqlite3 files into a completely different folder, and restart the server, an error should occur. 如果将两个.sqlite3文件都移到一个完全不同的文件夹中,然后重新启动服务器,则会发生错误。 If it doesn't, your server didn't properly restart - kill all ruby processes and try again. 如果不是,则您的服务器无法正确重启-杀死所有ruby进程,然后重试。

In answer to your question about migrating data, I had a similar problem recently, where I had to migrate from sqlite3 to mysql. 为了回答有关迁移数据的问题,最近我遇到了类似的问题,我不得不从sqlite3迁移到mysql。 Best solution I found was yaml_db . 我发现的最佳解决方案是yaml_db It seemed to do the job beautifully - add it to the project, then do 看起来做得不错-将其添加到项目中,然后执行

rake db:data:dump

Swap the database configurations (or migrate a new database file, or change your development environment, whatever it is you need to do to make an empty but structured database active), then: 交换数据库配置(或迁移新的数据库文件,或更改开发环境,使空的但结构化的数据库处于活动状态所需的任何操作),然后:

rake db:data:load

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

相关问题 无法加载此类文件— sqlite3 Ruby on Rails - Cannot Load Such File — sqlite3 Ruby on Rails Ruby on Rails将数据库和数据从SQLite3迁移到Postgres - Ruby on Rails migrate database and data from SQLite3 to Postgres 无法加载此类文件-sqlite3 / sqlite3_native(LoadError)在Rails上的ruby上 - cannot load such file — sqlite3/sqlite3_native (LoadError) on ruby on rails 无法加载此类文件-sqlite3 / sqlite3_native(LoadError)Ruby on Rails - cannot load such file — sqlite3/sqlite3_native (LoadError) Ruby on Rails Windows / Ruby / Rails安装 - 。无法加载这样的文件--sqlite3 / sqlite3_native windows - Windows/Ruby/Rails install — .cannot load such file — sqlite3/sqlite3_native windows windows 10 ruby​​2.5 rails 5.1.5无法加载这样的文件--sqlite3 / sqlite3_native(LoadError) - windows 10 ruby2.5 rails 5.1.5 cannot load such file — sqlite3/sqlite3_native (LoadError) 无法加载此类文件——在 ruby​​ on rails 上的 sqlite3/sqlite3_native (LoadError) - cannot load such file -- sqlite3/sqlite3_native (LoadError) on ruby on rails Ruby on Rails-SQLite3 - Ruby on Rails - Sqlite3 无法为Windows 10的Ruby on Rails 5加载sqlite3 - Can't load sqlite3 for Ruby on Rails 5 for Windows 10 将Java应用程序连接到Ruby on Rails SQLite3数据库 - Connecting Java Application to Ruby on Rails SQLite3 Database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM