【发布时间】:2014-04-02 04:08:57
【问题描述】:
我所有的测试都出错了。我试着整理了好一阵子,无济于事。它们类似于以下内容:
30) Error:
UserTest#test_a_user_should_enter_a_first_name:
ActiveRecord::StatementInvalid: SQLite3::SQLException: table events has no column named user_id: INSERT INTO "ev
ents" ("text", "event_start", "user_id", "created_at", "updated_at", "id") VALUES ('MyText', '2012-08-10', 20790
7133, '2014-04-02 03:43:47', '2014-04-02 03:43:47', 980190962)
31) Error:
UserTest#test_a_user_should_enter_a_last_name:
ActiveRecord::StatementInvalid: SQLite3::SQLException: table events has no column named user_id: INSERT INTO "ev
ents" ("text", "event_start", "user_id", "created_at", "updated_at", "id") VALUES ('MyText', '2012-08-10', 20790
7133, '2014-04-02 03:43:47', '2014-04-02 03:43:47', 980190962)
32) Error:
UserTest#test_a_user_should_have_a_profile_name_without_spaces:
ActiveRecord::StatementInvalid: SQLite3::SQLException: table events has no column named user_id: INSERT INTO "ev
ents" ("text", "event_start", "user_id", "created_at", "updated_at", "id") VALUES ('MyText', '2012-08-10', 20790
7133, '2014-04-02 03:43:47', '2014-04-02 03:43:47', 980190962)
我应该提一下,该应用程序本身运行良好。各种东西都依赖于 user_id 属性,它们会运行。
至于测试,我环顾四周,发现提到了Check your fixtures file! Whenever I'd rename columns, I'd usually forget to tweak my fixtures to match. This causes an error on every single test, just like you're seeing. Error in all unit and functional tests after altering column names of a table 不确定这是否适用于我的问题。如您所见,它表示事件已经有一个 user_id。我不太明白所有测试是如何失败的,即使是看似无关的测试。这就是让我失望的原因。
我的 GitHub 板块:https://github.com/attatae/and_silva
我需要将 user_id 插入 xxyynum_create_events.rb 吗?
ie integer :user_id下create table :events do |t|
我尝试过的其他事情: 耙分贝:测试:准备 rake db:migrate RAILS_ENV=test 删除然后重新创建数据库
非常感谢所有帮助。
更新================
发布后,我将 [bignum]_create_events.rb 更改为如下所示:
class CreateEvents < ActiveRecord::Migration
def change
create_table :events do |t|
t.string :title
t.datetime :time_begin
t.string :location
t.date :event_start
t.text :text
t.integer :user_id
t.text :user
t.timestamps
end
end
end
然后我尝试做bundle exec rake db:reset && bundle exec rake db:populate && bundle exec rake db:test:prepare,但收到错误“不知道如何构建任务'db:populate'。
所以我尝试了bundle exec rake db:drop && bundle exec rake db:create && bundle exec rake db:migrate && bundle exec db:test:prepare,但它说
no such table: events: ALTER TABLE "events" ADD "address" varchar(255)C:/Rails Projects/Git pull/and_silva/db/migrate/20140329045140_add_address_to_event.rb:3:inchange'`
接下来我进入了开发和测试沙箱,他们都说Event(Table doesn't exist)。
然后我尝试运行 rails s 只是为了确保我什至尝试修复正确的程序,因为我的应用程序之前运行得很好,显然事件中没有 user_id 方面。
该网站说Migrations are pending; run 'rake db:migrate RAILS_ENV=development' to resolve this issue. 我尝试运行 rake db:migrate 代替。然后说:
== AddAddressToEvent: migrating ==============================================
-- add_column(:events, :address, :string)
rake aborted!
An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: no such table: events: ALTER TABLE "events" ADD "address" varchar(255)C:/Rails Projects/Git pull/and_silva/db/migrate/20140329045140_add_address_to_event.rb:3:in *change'
C:in `migrate'
Tasks: TOP => db:migrate
然后我运行 rake 并在 32 次测试中得到与以前相同的错误。
我运行了 rake db:migrate RAILS_ENV=development,然后得到了相同的 AQLite3 [...] ALTER TABLE 错误。
【问题讨论】:
标签: ruby-on-rails