Rails rake db:migrate 没有效果
我今天制作了一个新的 Rails 3 应用程序,添加了一个简单的迁移,但由于某种原因,当我执行 rake db:migrate 时没有任何反应。它只是暂停几秒钟,然后返回到命令提示符,没有错误或任何内容。 Schema.rb 和数据库保持为空。
有什么想法可能会发生什么吗?我制作了很多应用程序,但从来没有遇到过这个问题。一切也都是完全标准的设置。
I made a new Rails 3 app today, added a simple migration, and for some reason, nothing happens when I do rake db:migrate. It simply pauses a few seconds, then returns to the command prompt, with no errors or anything. Schema.rb and the database stay empty.
Any ideas what could be going on? I've made many apps and never had this problem. Everything is a totally standard setup too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
迁移无法运行的原因有多种,但最常见的是系统已经认为您定义的所有迁移都已运行。
每次迁移都会在
schema_migrations
表中创建一个条目,其中version
列与标识符号相对应。如果您想强制重新运行迁移,通常可以将其退出并重试。例如,如果您有20100421175455_create_things.rb
,那么您可以使用以下方法重新运行它:常见情况是您的迁移一开始就无法运行,例如它生成了异常,并且但 Rails 仍然认为它是完整的。要强制重新运行迁移,请从
schema_migrations
表中删除相应记录,然后再次运行rake db:migrate
。将来避免此类问题的一种方法是使用自动退出过程定义迁移:
如果迁移中出现错误,您将看到控制台上列出的异常。由于迁移已自动回滚,您应该能够一次又一次地运行它,直到正确为止。
There's a few reasons why your migrations won't run, but the most common is that the system is already under the impression that all the migrations you've defined have already run.
Each migration creates an entry in the
schema_migrations
table with theversion
column corresponding to the identifier number. If you want to force a migration to re-run you can usually back it out and retry it. For example, if you had20100421175455_create_things.rb
then you would re-run it using:A common situation is that your migration has failed to run in the first place, that it generated an exception for instance, and yet Rails still considers it complete. To forcibly re-run a migration, delete the corresponding record from the
schema_migrations
table and runrake db:migrate
again.One way to avoid this kind of problem in the future is to define your migrations with an automatic back-out procedure:
If you have a mistake in your migration you will see the exception listed on the console. Since the migration has automatically been rolled back you should be able to run it again and again until you get it right.
我遇到了同样的问题。我做了一个简短的技巧,对我有帮助。我发布它只是为了以防万一有人想要一个简短而甜蜜的解决方案。我同意塔德曼的说法
我所做的是更改 /app_folder/db/migrate 文件夹中迁移文件的名称。我认为 ruby 迁移文件名称中的数字部分是文件创建的时间。
每次您想重新运行迁移时,都可以在文件名中添加 1 ,然后删除/删除表(我使用 mysql 命令行工具进行删除)。然后运行rake db:migrate并且应该完成迁移。
I faced the same problem. I did a kind of a short hack that helped me. I am posting it just in case anyone wants a short and sweet solution. I agree with what Tadman is saying
What I did was to change the name of the migrate file in the /app_folder/db/migrate folder. I think the numeric part in the name of the ruby migrate file is the time at which the file was created.
You can add say 1 , to the filename, every time you want to re-run the migrate. After changing the name drop/delete the table (I used mysql command line tool for deleting) and then run rake db:migrate and the migrations should be done.
调用
spring stop
可能会解决您的问题。Calling
spring stop
might solve your problems.好吧,我发现是什么导致了我的问题。我正在使用 slim_scrooge gem 并将其注释掉使一切正常进行。虽然不知道为什么...
Well, I found out what was causing my problem. I'm using the slim_scrooge gem and commenting it out makes everything proceed normally. Don't know why though...
我今天在使用插件迁移 Redmine 插件时遇到了类似的问题,
其中plugin_name实际上是插件 init.rb 中定义的插件名称。
我挣扎了4个小时,终于发现我的插件目录名称与插件名称不一样(注意
redmine_
前缀):所以,请确保您的插件放置在以插件名称命名的文件夹中。我相信它也适用于其他 Rails 应用程序。
I faced similar problem today while migrating plugin for Redmine using
where plugin_name is actually plugin name defined in init.rb of the plugin.
I struggled for 4 hours and finally figured out that my plugin directory name was not the same as the plugin name (note
redmine_
prefix):So, make sure your plugin is placed in folder named after plugin name. I believe it applies to other rails apps as well.