【发布时间】:2014-12-16 13:11:00
【问题描述】:
我是 Ruby 和 Rails 的新手。所以这可能是一个简单的解决方法。如果是的话,我很抱歉。
我最近安装了 Ruby-on-Rails 并开始学习 rubyonrails.org 上的教程,该教程展示了如何制作一个简单的博客。在我进入第 5.5 节之前,一切都运行良好。我去运行 db:migrate,它给了我一个错误。
|D:\Documents\Programs\Ruby\blog>rake db:migrate
== 20141216061542 CreateArticles: migrating ===================================
-- create_table(:articles)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: table "articles" already exists: CREATE TABLE "articles" ("id" INTEGER
PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "text" text, "created_at" datetime,
"updated_at"
datetime) D:/Documents/Programs/Ruby/blog/db/migrate/20141216061542_create_articles.rb:3:in
`change
'
C:in `migrate'
ActiveRecord::StatementInvalid: SQLite3::SQLException: table "articles" already exists: CREATE
TABLE
"articles" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "text" text,
"created_at" datetime, "updated_at" datetime)
D:/Documents/Programs/Ruby/blog/db/migrate/20141216061542_create_articles.rb:3:in `change'
C:in `migrate'
SQLite3::SQLException: table "articles" already exists
D:/Documents/Programs/Ruby/blog/db/migrate/20141216061542_create_articles.rb:3:in `change'
C:in `migrate'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
我启动了服务器以查看它会显示什么,它给了我这个:
ActiveRecord::PendingMigrationError
Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development
从那以后它就一直这样做。我尝试通过删除项目重新开始。(不完全确定这是否是一个好的举措。)我尝试查看代码。我尝试过的任何事情都没有给我任何提示。
有没有办法摆脱这些错误?
提前谢谢你。
编辑: 我试图用 'rake db:reset' 重置数据库,但它只是给了我这个:
|D:\Documents\Programs\Ruby\blog\app\views\articles>rake db:reset
(in D:/Documents/Programs/Ruby/blog)
Permission denied @ unlink_internal - D:/Documents/Programs/Ruby/blog/db/development.sqlite3
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/fileutils.rb:1460:in `unlink'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/fileutils.rb:1460:in `block in remove_file'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/fileutils.rb:1468:in `platform_support'
...
rake aborted!
Errno::EACCES: Permission denied @ unlink_internal -
D:/Documents/Programs/Ruby/blog/db/development.
sqlite3
Tasks: TOP => db:schema:load
(See full trace by running task with --trace)
为了便于阅读,我缩短了它。
这是我的 create_articles 迁移文件:
class CreateArticles < ActiveRecord::Migration
def change
create_table :articles do |t|
t.timestamps
end
end
end
【问题讨论】:
-
您可以按照 Syed 的建议简单地重置您的数据库,而不是删除您的项目
-
显示您的 CreateArticles 迁移文件
-
问题可能出在您的数据库配置文件中
-
我对 Rails 的工作原理知之甚少,不知道要寻找什么。有什么资源可以提供帮助吗?
标签: ruby-on-rails ruby rake dbmigrate