本文介绍了$rake db:migrate 发生了一个错误,这次和所有以后的迁移都被取消了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 RoR 的新手,我不断收到此错误消息:

I am new to RoR and I keep getting this error message:

$ rake db:migrate
==  CreateUsers: migrating ====================================================
-- create_table(:users)
rake aborted!
An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: table "users" already exists: CREATE TABLE "users" ("id"
INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "email" varchar
(255), "created_at" datetime, "updated_at" datetime)

Tasks: TOP => db:migrate
(See full trace by running task with --trace)

我已经寻找了 3 天的解决方案,但似乎找不到任何适合我的方法.

I've been searching for a solution for 3 days, but I cannot seem to find anything that works for me.

预先感谢您的帮助:)PS - 我正在运行 Windows.

Thank you in advance for your help :)PS - I am running off Windows.

推荐答案

table "users" already exists 似乎是问题所在.您是否尝试使用某些 SQLITE 管理工具从数据库中手动删除该表?

table "users" already exists seems to be the problem. Have you tried to manually remove the table from your database with some SQLITE admin tool?

或者您可以在迁移脚本中包含一个删除表(应该在您的 db/migrate 文件夹中称为 create_users.rb).在 def up 中插入 drop_table :users :

Or you can include a remove table in your migration script (should be called create_users.rb inside your db/migrate folder). Inside def up insert drop_table :users :

      def up
         drop_table :users

         create_table :users do |t|
         t.string :name
         #...

         t.timestamps
      end

哦,我记得在我的 RoR 时间里,表名Users"可能会在以后引起问题.这可能是相关的.

Oh and I remember from my RoR time that the table name "Users" can cause problems later on. Might be this is related.

这篇关于$rake db:migrate 发生了一个错误,这次和所有以后的迁移都被取消了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 03:43