如何将数据从生产数据库迁移到开发数据库 (Rails 4)?

编程入门 行业动态 更新时间:2024-10-28 08:23:45
本文介绍了如何将数据从生产数据库迁移到开发数据库 (Rails 4)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道这听起来有点倒退!我一直在研究基于云的案例管理应用程序,并且正在研究支持票务功能.我们的开发数据库 (MySQL) 拥有与生产数据库相同的数据(这是一个非常大的应用程序).开发基本上是一个沙箱"环境,因此为什么开发数据库与生产数据库完全相同.今天早上,我在本地开发服务器中遇到了一个问题:

I know this one sounds kind of backwards! I've been working on a cloud-based case-management application, and was working on a support-ticketing feature. We have our development database (MySQL) that has all the same data as our production database (It's a very large app). Development is basically a "sandbox" environment, hence why the development db has all the same as the production db. This morning, I ran into a problem in my local development server for:

Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=development' to resolve this issue.

好吧,尽管这样做没有任何意义.它出错了,因为它试图创建已经存在的表(我已经运行了我的迁移,功能在一天前完成了!一切都很好).

Alright, did that, even though it didn't make any sense. It err'd out, because it was trying to create tables that already existed (I had already ran my migrations, the features were completed a day ago! And everything worked great).

在我的开发服务器收到这条消息之前,我唯一做的就是取消注释一个完全注释掉的文件,以尝试修复 TinyMCE(/config/tinymce.yml,文本编辑器)的问题,然后是重新启动我的 Rails 开发服务器.所有这些文件都是一堆默认值和插件.当我看到问题时,我首先将它们全部注释掉.还是一样的错误.继续 rake db: 任务.

The only thing that I did the moment before I got this message in my development server was uncomment an entirely-commented-out file to try and fix problems with TinyMCE (/config/tinymce.yml, text editor), followed by restarting my rails dev server. All this file was, was a bunch of defaults and plugins. When I saw the problem, I first commented them all back out. Still the same error. Proceeded with rake db: tasks.

开始寻找答案..不断出错.犯了一个菜鸟错误,最终做了一个

Started looking for answers.. kept getting errors. Made a noob mistake, and ultimately did a

rake db:migrate:reset

我知道它会以托管数据库为代价重建架构.这失败了..但我们确实在不止一个地方有数据库(因为它与生产相同.)此外,只是尝试将所有表带回来:

which I knew would rebuild the schema at the cost of hosing the db. This failed.. But we do have the db in more than one place (since it's the same as production.) Also, just to try and bring all the tables back:

rake db:schema:load

....在其中一张桌子上失败了

....failed on one of the tables anyway with

ActiveRecord::StatementInvalid: Mysql2::Error: Specified key was too long; max key length is 767 bytes: CREATE UNIQUE INDEX `login` USING btree ON `users` (`login`, `intranet_id`)

..并且所有成功创建的表都是空的(如预期的那样).我绝不是数据库专家(我的开发时间不长).想知道,有没有办法将整个生产数据库复制到开发数据库中?表、数据和所有.或者有什么其他建议?真的输了.

..and all the tables are empty (as expected) that were successfully created. I'm by no means a database pro (I haven't dev'd very long). Am wondering, is there a way to copy the entire production database into the devel database? Tables, data, and all. Or any other suggestions? Really lost on this one.

推荐答案

您可以使用 mysql_dump.

如果您连接到数据库,一切都在那里 - 您只需要转储整个数据库,然后再次转储到生产表中.

If you connect to the database everything is there - you just have to do a dump of the full database and then do the dump again into the production tables.

正如您清楚地看到的,您可以使用>"从数据库中输出,也可以使用<"导入.

As you clearly see you can output from the database with ">" and you can import with the "<".

更多推荐

如何将数据从生产数据库迁移到开发数据库 (Rails 4)?

本文发布于:2023-10-24 09:06:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1523526.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   如何将   数据   Rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!