rake db:尝试插入时迁移失败

发布于 2024-08-31 09:23:34 字数 1037 浏览 7 评论 0原文

我正在尝试填充数据库,以便我可以开始项目。这个项目已经建成,我被邀请来帮助前端工作。问题是我无法让 rake db:migrate 进行任何插入。每次运行 rake db:migrate 时,我都会得到这样的信息:

== 20081220084043 CreateTimeDimension: migrating ==============================
-- create_table(:time_dimension)
   -> 0.0870s
INSERT time_dimension(time_key, `year`, `month`, `day`, day_of_week, weekend, quarter) VALUES(20080101, 2008, 1, 1, 'Tuesday', false, 1)
rake aborted!
Could not load driver (uninitialized constant Mysql::Driver)

我正在使用 Snow Leopard 构建 MBP。我已经从以下位置安装了 XCode mac 自带的磁盘。我已经更新了 ruby​​,安装了 Rails 并 所有需要的宝石。我安装了 64 位版本的 MySQL。

我尝试过 32 位版本的 MySQL,甚至尝试过 从 macports 安装

mysql gem 使用以下命令安装: sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/path/to/mysql/bin/mysql_config

迁移创建表很好,但每次尝试插入时都会死掉。

任何帮助都会很棒

I'm trying to get a database populate so I can begin working on a project. This project is already built and I'm being brought in to help with front-end work. Problem is I can't get rake db:migrate to do any inserts. Every time I run rake db:migrate I get this:

== 20081220084043 CreateTimeDimension: migrating ==============================
-- create_table(:time_dimension)
   -> 0.0870s
INSERT time_dimension(time_key, `year`, `month`, `day`, day_of_week, weekend, quarter) VALUES(20080101, 2008, 1, 1, 'Tuesday', false, 1)
rake aborted!
Could not load driver (uninitialized constant Mysql::Driver)

I'm building on a MBP with Snow Leopard. I've installed XCode from the
disk that comes with the mac. I've updated ruby, installed rails and
all the needed gems. I have the 64 bit version of MySQL installed.

I've tried the 32 bit version of MySQL and I've even tried installing from macports.

The mysql gem is installed using: sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/path/to/mysql/bin/mysql_config

the migrate creates the tables just fine but it dies every single time it tries an insert.

Any help would be great

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

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

发布评论

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

评论(4

时光沙漏 2024-09-07 09:23:34

这些安装 MySQL 的说明在 Mac OS X Snow Leopard 上非常适合我: http: //hivelogic.com/articles/compiling-mysql-on-snow-leopard

These instructions for installing MySQL worked great for me on Mac OS X Snow Leopard: http://hivelogic.com/articles/compiling-mysql-on-snow-leopard

离去的眼神 2024-09-07 09:23:34

如果在控制台上运行“mysql -u root”工作正常,则可以使用 hivelogic.com 中的说明(按照 John Topley 的链接)重新安装 mysql gem,方法是输入以下内容:

sudo gem install mysql -- --with-mysql -dir=/usr/local/mysql

如果您将 MySQL 64 位安装为 pkg,请尝试通过手动编译重新安装。

If running 'mysql -u root' on your console works fine, then possibly reinstall your mysql gem using the instructions from hivelogic.com (as per John Topley's link) by typing this instead:

sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql

If you installed MySQL 64-bit as a pkg, try reinstalling by manual compile.

久光 2024-09-07 09:23:34

一方面提示:数据库迁移不利于播种。如果您使用rails >= 2.3.4,那么您应该为此使用 db/seeds.rb 和 $ rake db:seed 任务。

Tip on a side: Database migration is bad for seeding. If you use rails >= 2.3.4 then you should use db/seeds.rb and $ rake db:seed task for this.

雪花飘飘的天空 2024-09-07 09:23:34

鉴于您收到的错误,看来您不需要 mysql gem。
其他潜在的问题:

  1. 安装 gem 后忘记重新启动应用程序/服务器。
  2. 您的 mysql 用户权限存在某种问题。 (例如:没有写入权限)
  3. 您使用了错误的 mysql 驱动程序/gem。

编辑:如果您在 Mac 上进行 ruby​​ 开发,我强烈建议同时使用 homebrewrvm

Given the error you were getting, it looks like you haven't required the mysql gem.
Other potential gotchas:

  1. You forgot to restart your application/server after installing the gem.
  2. You have some sort of problem with the mysql user permissions. (eg: no write privs)
  3. You're using the wrong mysql driver/gem.

Edit: If you're doing ruby dev on Mac, I highly recommend using both homebrew and rvm.

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