尝试创建模型时,“rails generate"命令挂起 [英] 'rails generate' commands hang when trying to create a model

查看:49
本文介绍了尝试创建模型时,“rails generate"命令挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Rails 的新手,今天早上决定转储我的整个数据库设计/模型并重新开始.作为一个菜鸟,我肯定做错了.

I'm new to rails and decided this morning to dump my whole database design/model and start over. And being a noob, I'm sure did it incorrectly.

我删除了 db/migrate/ 中的所有文件并删除了表.当我尝试生成第一个新模型类时,rails 就挂了.在我点击 ^C 并尝试其他东西之前,在杂草中休息了 10 分钟.

I removed all the files in db/migrate/ and dropped the tables. And when I tried to generate the first new model class, rails just hung. Off in the weeds for 10 minutes before I hit ^C and tried something else.

这一次,我再次删除表,将整个项目移至 project.bad 并运行 rails new 重新开始.同样,在用旧名称生成新项目后,它挂在 rails generate 命令上(我使用的是相同的项目名称).

This time, I again dropped the tables, moved the whole project to project.bad and ran rails new to start over. Again, after generating the new project with the old name, it hung on the rails generate command (I was using the same project name).

无奈之下,我尝试在同一个根目录中创建一个新项目,但使用另一个名称.尤里卡!这就像一个冠军,创建控制器和模型类,但我完全无法在原始项目或任何新创建的项目中使用原始项目名称生成任何内容.我错过了什么才能让它再次工作?我不介意此时完全丢失,但我希望能够再次使用原始项目名称!

In desperation, I tried creating a new project in the same root, but with another name. Eureka! This worked like a champ, creating controllers and model classes, but I'm completely unable to generate anything using the original project name, in the original project or any newly-created one. What am I missing to get this working again? I don't mind a complete loss at this point, but I'd like to be able to use the original project name again!

这是 log/development.log 的样子:

Here's what log/development.log looks like:

   (255.5ms)  CREATE TABLE `schema_migrations` (`version` varchar(255) NOT NULL) ENGINE=InnoDB
   (337.7ms)  CREATE UNIQUE INDEX `unique_schema_migrations`  ON `schema_migrations` (`version`) 
  ActiveRecord::SchemaMigration Load (0.2ms)  SELECT `schema_migrations`.* FROM `schema_migrations`
   (0.2ms)  SELECT `schema_migrations`.`version` FROM `schema_migrations`

知道在最后一次 SELECT 之后会发生什么吗?

Any idea what's supposed to happen after that last SELECT?

推荐答案

如果您的 rails generate 命令挂起,很可能是生成的 rails binstubs 有问题.正如您所提到的,您重命名了该项目.

If your rails generate commands hangs, it is most likely that the generated binstubs of rails are the issue. As you mentioned, you renamed the project.

我有根据的猜测是 binstubs 中的某些路径仍然设置为旧项目目录,但不再存在.

My educated guess is that some paths in the binstubs were still set to the old project directory but did not exist any longer.

这里有一篇关于 binstubs 如何工作的很棒的文章:https://github.com/sstephenson/rbenv/wiki/Understanding-binstubs

There is a great article on how binstubs work here: https://github.com/sstephenson/rbenv/wiki/Understanding-binstubs

导轨 4

要重置 binstub,只需删除 rails 中的 bin/ 目录并运行:

To reset the binstubs, just delete your bin/ directory in rails and run:

# generates binstubs for ALL gems in the bundle
bundle install --binstubs

# ...OR, generate binstubs for a SINGLE gem (recommended)
bundle binstubs rake

导轨 5/导轨 6

要重置 binstub,只需删除 rails 中的 bin/ 目录并运行:

To reset the binstubs, just delete your bin/ directory in rails and run:

rake app:update:bin

为什么我们需要对 rails 5 及更高版本使用rake"命令,而不是rails"命令本身?

从 rails 5 开始,一些 'rake' 命令被封装在 'rails' 命令中.然而,当删除 'bin/' 目录时,同时也删除了 'rails' 命令本身,因此需要返回 'rake' 进行重置,因为 'rails' 不再可用,但 'rake' 仍然可用.

这篇关于尝试创建模型时,“rails generate"命令挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆