rake db:尝试插入时迁移失败
我正在尝试填充数据库,以便我可以开始项目。这个项目已经建成,我被邀请来帮助前端工作。问题是我无法让 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这些安装 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
如果在控制台上运行“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.
一方面提示:数据库迁移不利于播种。如果您使用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.鉴于您收到的错误,看来您不需要 mysql gem。
其他潜在的问题:
编辑:如果您在 Mac 上进行 ruby 开发,我强烈建议同时使用 homebrew和 rvm。
Given the error you were getting, it looks like you haven't required the mysql gem.
Other potential gotchas:
Edit: If you're doing ruby dev on Mac, I highly recommend using both homebrew and rvm.