Ruby-on-rails $rake db:migrate 发生了一个错误,这次和所有以后的迁移都被取消了
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8589874/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
$rake db:migrate An error has occurred, this and all later migrations canceled
提问by Michele
I am new to RoR and I keep getting this error message:
我是 RoR 的新手,我不断收到此错误消息:
$ 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)
I've been searching for a solution for 3 days, but I cannot seem to find anything that works for me.
我一直在寻找解决方案 3 天,但似乎找不到任何适合我的方法。
Thank you in advance for your help :) PS - I am running off Windows.
预先感谢您的帮助 :) PS - 我正在运行 Windows。
采纳答案by Pete
table "users" already existsseems to be the problem. Have you tried to manually remove the table from your database with some SQLITE admin tool?
table "users" already exists似乎是问题所在。您是否尝试使用某些SQLITE 管理工具从数据库中手动删除表?
Or you can include a remove table in your migration script (should be called create_users.rb inside your db/migrate folder). Inside def upinsert drop_table :users:
或者,您可以在迁移脚本中包含一个删除表(应在 db/migrate 文件夹中称为 create_users.rb)。内def up插drop_table :users:
def up
drop_table :users
create_table :users do |t|
t.string :name
#...
t.timestamps
end
Oh and I remember from my RoR time that the table name "Users" can cause problems later on. Might be this is related.
哦,我记得在我的 RoR 时间里,表名“Users”可能会在以后引起问题。可能是这个有关系。
回答by user3350457
Not sure if you are following Michael Hartl's tutorial on RoR.
不确定您是否正在关注 Michael Hartl 关于 RoR 的教程。
But someone has said there's a problem in the steps of the tutorial http://archive.railsforum.com/viewtopic.php?id=44944
但是有人说教程http://archive.railsforum.com/viewtopic.php?id=44944的步骤有问题
rake db:drop:all<---------- will wipe everythingthen run rake db:migrateagain should fix the problem.
rake db:drop:all<--------- 将擦除所有内容然后rake db:migrate再次运行应该可以解决问题。
Good Luck
祝你好运
回答by Brian Enriquez
Because the table already exists, you need to delete/remove it before executing the migration.
由于该表已经存在,您需要在执行迁移之前删除/移除它。
Easy, GUI way to do this is with the SQLite Database Browser (http://sourceforge.net/projects/sqlitebrowser/).
使用 SQLite 数据库浏览器 ( http://sourceforge.net/projects/sqlitebrowser/) 可以轻松完成此操作。
Click the button with the Table-X icon. Choose User Table click Delete.
单击带有 Table-X 图标的按钮。选择用户表单击删除。
Then run rake db:migrate
然后运行 rake db:migrate
Bada boom bada bing
八达轰八达冰
回答by tenzin dorjee
I had a similar problem, then i did
=> rake db:drop=> rake db:create=> rake db:migrate
我遇到了类似的问题,然后我做了 => rake db:drop=> rake db:create=>rake db:migrate
worked perfectly.
完美地工作。
But if it doesn't work we could try something like
但如果它不起作用,我们可以尝试类似
ActiveRecord::Migration.drop_table('users')
ActiveRecord::Migration.drop_table('users')
ActiveRecord::Migration.create_table('users')
ActiveRecord::Migration.create_table('users')
回答by Stefano
I had the same problem and after several hours I finally found the solution
我遇到了同样的问题,几个小时后我终于找到了解决方案
I've put def self.up
我已经把 def self.up
create_table :users do |t|
create_table :用户做 |t|
def down drop_down :users end end
def down drop_down :users end end
Then make rake db:migrate and Magic !!!!
然后制作 rake db:migrate 和 Magic !!!!

