rake db:migrate 不起作用

编程入门 行业动态 更新时间:2024-10-12 12:24:17
本文介绍了rake db:migrate 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在学习 rails 教程,但被卡住了.从代码清单 8.16 开始,我对 _add_remember_token_to_users.rb 做了以下修改:

I'm working through the rails tutorial and have gotten stuck. Starting at Listing 8.16 I have made the following modifications to <timestamp>_add_remember_token_to_users.rb:

class AddRememberTokenToUsers < ActiveRecord::Migration def change add_column :users, :remember_token, :string add_index :users, :remember_token end end

然后指南说要更新 dev &照常测试数据库:

The guide then says to update dev & test db as usual:

$ bundle exec rake db:migrate $ bundle exec rake db:test:prepare

我对 *remember_token* 的用户测试仍然失败,所以我使用命令行 sqlite3 查看了 dev 和 tests 数据库中的 user 表.它们看起来像这样:

My User test for the *remember_token* is still failing so I took a look at the user table in dev and tests database with command line sqlite3. They look like this:

sqlite> .schema users CREATE TABLE "users" ( "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "email" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "password_digest" varchar(255)); CREATE UNIQUE INDEX "index_users_on_email" ON "users" ("email");

我的迁移似乎还没有运行,但我不知道如何强制它运行.

It seems like my migration has not been run yet but I do not know how to force it to run.

推荐答案

尝试重建你的数据库结构(警告:所有的数据库数据都将丢失):

Try to rebuild your database structure(WARNING: all db-data will be lost):

rake db:drop:all rake db:create:all rake db:migrate

如果你使用 Rails <4.1、不要忘记准备测试数据库:

If you use Rails < 4.1, don't forget to prepare test database:

rake db:test:prepare

这是最简单的解决方案,因为您正在使用教程.但是,在生产中或在开发中有重要数据时,您应该花时间调查问题.在这种情况下,您很可能创建了一个空迁移,运行了 rake db:migrate,然后向迁移添加了说明,因此您看不到新字段和进一步的 rake db:migrate 什么都不做.要解决此问题,您需要注释 change 指令,执行 rake db:rollback,取消注释指令,然后 rake db:migrate 以应用指令你错过了.

This is the easiest solution since you are working with tutorial. However in production or having important data in development you should take time to investigate the issue. In this case you most likely had created an empty migration, ran rake db:migrate, then added instructions to the migration, so you don't see a new field and further rake db:migrate does nothing. To resolve this issue you need to comment your change instructions, perform rake db:rollback, uncomment instructions and then rake db:migrate to apply instructions you missed.

更多推荐

rake db:migrate 不起作用

本文发布于:2023-10-18 15:10:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504593.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   rake   db   migrate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!