简体   繁体   English

无法在cmd行Ruby on Rails中生成模型

[英]Cannot generate a model in cmd line Ruby on Rails

I just started learning ruby on rails today. 我今天才刚开始学习红宝石。 I am following the book Rails For PHP Developers. 我关注的是Rails For PHP Developers。 Anyhow, when I type rails g model Subscribers the next line says "invoke active record". 无论如何,当我输入rails g model Subscribers时,下一行会显示“调用活动记录”。 I had no trouble creating a controller from the cmd line, so how come my model is not generating. 我从cmd线创建控制器没问题,所以我的模型为什么不生成。 Which means the model file is not being created in models directory. 这意味着未在models目录中创建模型文件。

You need to add the mysql2 gem to your gemfile. 您需要将mysql2 gem添加到您的gemfile中。 Then run bundle install and try it again. 然后运行捆绑安装,然后重试。

When learning rails and on your local machine it's best to stay with the defaul SQLite database. 当学习rails并在本地计算机上时,最好保留默认的SQLite数据库。 You must have changed the config/database.yml to use MySQL for your development environment and that requires you to have the MySQL adapter installed. 您必须更改config / database.yml才能在开发环境中使用MySQL,并且这需要安装MySQL适配器。

Note: Use the mysql2 gem, not the mysql gem. 注意:请使用mysql2 gem,而不是mysql gem。 It'll save you a lot of grief. 它将为您节省很多痛苦。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM