Rails add_test_data 迁移

发布于 2024-08-11 15:47:12 字数 892 浏览 1 评论 0原文

刚刚读完《使用 Rails 进行敏捷 Web 开发》一书并在该书的最后几章附近,我不得不使用 db:migrate VERSION=0 和 db:migrate 命令回滚数据库几次。然而,当数据库从头开始恢复时,add_test_data 迁移无法像之前成功完成的那样将测试条目添加到数据库中。有什么想法吗?我在开发日志中收到以下内容

迁移到 AddTestData (20091111225948) [4;36;1mSQL (0.0ms)[0m [0;1mselect sqlite_version(*)[0m

[4;35;1m产品加载 (1.0ms)[0m [0m SELECT "products".id FROM "products" WHERE ("products"."title" = '实用项目自动化') LIMIT 1[0m

[4;36;1m产品负载 (0.0ms)[0m [0;1mSELECT "products".id FROM "products" WHERE ("products"."title" = '实用版本控制') LIMIT 1[0m

[4;35;1mProduct Load (1.0ms) )[0m [0mSELECT "products".id FROM "products" WHERE ("products"."title" = '实用单元测试 (C#)') LIMIT 1[0m

[4;36;1mSQL (1.0ms)[0m [0;1mINSERT INTO schema_migrations (version) VALUES ('20091111225948')[0m

数据库是 SQLite3,Ruby 1.8.6,Rails 2.3.4,我在 Windows 上开发(畏缩)

Just working through the Agile Web Development with Rails book and near the closing chapters of the book I had to rollback the db a few times using db:migrate VERSION=0 followed by the db:migrate command. However upon bringing the database back from the ground up, the add_test_data migration fails to add the test entries to the db as it had successfully done previously. Any Ideas? Im getting the following in the development log

Migrating to AddTestData (20091111225948)
[4;36;1mSQL (0.0ms)[0m [0;1mselect sqlite_version(*)[0m

[4;35;1mProduct Load (1.0ms)[0m [0m
SELECT "products".id FROM "products" WHERE ("products"."title" = 'Pragmatic Project Automation') LIMIT 1[0m

[4;36;1mProduct Load (0.0ms)[0m [0;1mSELECT "products".id FROM "products" WHERE ("products"."title" = 'Pragmatic Version Control') LIMIT 1[0m

[4;35;1mProduct Load (1.0ms)[0m [0mSELECT "products".id FROM "products" WHERE ("products"."title" = 'Pragmatic Unit Testing (C#)') LIMIT 1[0m

[4;36;1mSQL (1.0ms)[0m [0;1mINSERT INTO schema_migrations (version) VALUES ('20091111225948')[0m

The db is SQLite3, Ruby 1.8.6, Rails 2.3.4 and im developing on Windows (cringe)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苏别ゝ 2024-08-18 15:47:12

由于您使用的是 2.3.4,我将使用 db:seed 添加种子数据。

除此之外,我会尝试重命名您的 sqlite 数据库并针对空数据库再次运行 rake db:migrate 。您可能必须创建一个新的空development.sqlite3。

如果这些都不适合您,那么发布迁移内容将会有所帮助。

Since you're using 2.3.4 I would use db:seed to add seed data.

Short of that I'd try renaming your sqlite database and running rake db:migrate again against an empty database. You might have to create a new empty development.sqlite3.

If neither of these work for you posting the contents of the migration would help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文