$rake db:migrate 发生错误,本次迁移和所有后续迁移均被取消

发布于 2024-12-22 05:03:27 字数 621 浏览 1 评论 0原文

我是 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)

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

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

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)

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

且行且努力 2024-12-29 05:03:27

不确定您是否正在关注 Michael Hartl 的 RoR 教程。

但有人说教程 http://archive.railsforum 的步骤有问题。 com/viewtopic.php?id=44944

rake db:drop:all <---------- 将擦除所有内容然后运行耙子db:migrate 再次应该可以解决问题。

祝你好运

Not sure if you are following Michael Hartl's tutorial on RoR.

But someone has said there's a problem in the steps of the tutorial http://archive.railsforum.com/viewtopic.php?id=44944

rake db:drop:all <---------- will wipe everything then run rake db:migrate again should fix the problem.

Good Luck

中性美 2024-12-29 05:03:27

表“users”已经存在似乎是问题所在。您是否尝试过使用某些 SQLITE 管理工具 手动从数据库中删除该表?

或者,您可以在迁移脚本中包含删除表(应在 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

哦,我记得在我的 RoR 时间里,表名“Users”可能会在以后引起问题。可能这有关系。

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?

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

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

风向决定发型 2024-12-29 05:03:27

由于该表已经存在,因此在执行迁移之前需要删除/移除它。

简单的 GUI 方法可以使用 SQLite 数据库浏览器 (http://sourceforge.net/projects/sqlitebrowser/ )。

单击带有 Table-X 图标的按钮。选择用户表单击删除。

然后运行rake db:migrate

Badaoom bada bing

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/).

Click the button with the Table-X icon. Choose User Table click Delete.

Then run rake db:migrate

Bada boom bada bing

北城挽邺 2024-12-29 05:03:27

我遇到了同样的问题,几个小时后我终于找到了

我提出的 解决方案
def self.up

create_table :用户做|t|

绝对向下
drop_down:用户
结尾
然后

进行 rake db:migrate 和 Magic !!!!

I had the same problem and after several hours I finally found the solution

I’ve put
def self.up

create_table :users do |t|

def down
drop_down :users
end
end

Then make rake db:migrate and Magic !!!!

要走就滚别墨迹 2024-12-29 05:03:27

我遇到了类似的问题,然后我就这么做了
=> rake db:drop
=> rake 数据库:创建
=> rake db:migrate

工作得很好。

但如果它不起作用,我们可以尝试类似

ActiveRecord::Migration.drop_table('users')

ActiveRecord::Migration.create_table('users')

I had a similar problem, then i did
=> 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.create_table('users')

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文